diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkTest.java index be717bda9..2aeefe50e 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkTest.java @@ -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; @@ -78,10 +79,8 @@ public void testDocumentLinkExternalFile() throws Exception { assertEquals("file://test0", hyperlinks[0].getHyperlinkText()); } - @Test - public void testDocumentLinkWithEncodedUri() throws Exception { - final var links = new ArrayList(); - 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 "); @@ -89,9 +88,18 @@ public void testDocumentLinkWithEncodedUri() throws Exception { 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(); diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java index f4e501da2..a06bba0f1 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java @@ -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; @@ -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; }