Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -78,20 +79,27 @@ public void testDocumentLinkExternalFile() throws Exception {
assertEquals("file://test0", hyperlinks[0].getHyperlinkText());
}

@Test
public void testDocumentLinkWithEncodedUri() throws Exception {
final var links = new ArrayList<DocumentLink>();
links.add(new DocumentLink(new Range(new Position(0, 9), new Position(0, 15)), "file:///tmp/fi%C3%A9le.ts"));
private void assertDocumentLinkWithEncodedUri(String encoded, String decoded) throws Exception{
final var links = List.of(new DocumentLink(new Range(new Position(0, 9), new Position(0, 15)), encoded));
MockLanguageServer.INSTANCE.setDocumentLinks(links);

IFile file = TestUtils.createUniqueTestFile(project, "not_link <link>");
ITextViewer viewer = TestUtils.openTextViewer(file);

IHyperlink[] hyperlinks = documentLinkDetector.detectHyperlinks(viewer, new Region(13, 0), true);
assertEquals(1, hyperlinks.length);
assertEquals("/tmp/fiéle.ts", hyperlinks[0].getHyperlinkText());
assertEquals(decoded, hyperlinks[0].getHyperlinkText());
}
@Test
public void testDocumentLinkWithFileEncodedUri() throws Exception {
assertDocumentLinkWithEncodedUri("file:///tmp/fi%C3%A9le.ts", "/tmp/fiéle.ts");
}

@Test
public void testDocumentLinkWithEncodedUri() throws Exception {
assertDocumentLinkWithEncodedUri("http://abc.com/fi%C3%A9le.html", "http://abc.com/fiéle.html");
}

@Test
public void testDocumentLinkWrongRegion() throws Exception {
final var links = new ArrayList<DocumentLink>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package org.eclipse.lsp4e.operations.documentLink;

import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -81,6 +83,8 @@ private static String toLabel(final String uri) {
} catch (final IllegalArgumentException ex) {
LanguageServerPlugin.logError(ex);
}
} else {
return URLDecoder.decode(uri, StandardCharsets.UTF_8);
}
return uri;
}
Expand Down
Loading