Skip to content

Commit 8b09c15

Browse files
committed
Fix non-ASCII characters in URI
1 parent 4072712 commit 8b09c15

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/edit/LSPEclipseUtilsTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ public void testToUri_WindowsUNC() {
342342
// Ensure there is an authority and no malformed quadruple slashes
343343
assertFalse(uriWithSpaces.toString().startsWith("file:////"));
344344
}
345+
346+
@Test
347+
void testFileURIWithNonAsciiPath() throws Exception {
348+
// File name contains a German Eszett and a Japanese Kana
349+
String fileName = "fooßア";
350+
IFile targetFile = project.getFile(fileName);
351+
assertEquals(fileName, Paths.get(LSPEclipseUtils.toUri(targetFile)).getFileName().toString());
352+
}
345353

346354
@Test
347355
public void testToWorkspaceFolder() {

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,15 +1353,19 @@ public static URI toUri(File file) {
13531353
final int slash = path.indexOf('/', 2);
13541354
final String authority = slash > 2 ? path.substring(2, slash) : path.substring(2);
13551355
final String absPath = slash > 2 ? path.substring(slash) : "/"; //$NON-NLS-1$
1356-
return new URI(FILE_SCHEME, authority, absPath, null);
1356+
return ensureAscii(new URI(FILE_SCHEME, authority, absPath, null));
13571357
}
1358-
return new URI(FILE_SCHEME, "", path, null); //$NON-NLS-1$
1358+
return ensureAscii(new URI(FILE_SCHEME, "", path, null)); //$NON-NLS-1$
13591359
} catch (URISyntaxException e) {
13601360
LanguageServerPlugin.logError(e);
13611361
return file.getAbsoluteFile().toURI();
13621362
}
13631363
}
13641364

1365+
private static URI ensureAscii(URI uri) {
1366+
return URI.create(uri.toASCIIString());
1367+
}
1368+
13651369
public static @Nullable IFile getFile(@Nullable IDocument document) {
13661370
IPath path = toPath(document);
13671371
return getFile(path);

0 commit comments

Comments
 (0)