Skip to content

Commit

Permalink
fix #2866 Prevent URL decoding of filenames for specific schemes.
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Jan 9, 2025
1 parent 541319b commit 162081c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ default String getFileName(final String url, final String encoding) {
u = u.substring(0, idx);
}
}
u = decodeUrlAsName(u, u.startsWith("file:"));
if (!u.startsWith("smb:") && !u.startsWith("smb1:") && !u.startsWith("ftp:")) {
u = decodeUrlAsName(u, u.startsWith("file:"));
}
idx = u.lastIndexOf('/');
if (idx >= 0) {
if (u.length() > idx + 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ public void test_getFileName_ok() throws Exception {
url = "smb://example.com/test?.txt";
exp = "test?.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "https://example.com/test%E3%81%82.txt";
exp = "testあ.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "file://example.com/test%E3%81%82.txt";
exp = "testあ.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "storage://example.com/test%E3%81%82.txt";
exp = "testあ.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "smb://example.com/test%E3%81%82.txt";
exp = "test%E3%81%82.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "smb1://example.com/test%E3%81%82.txt";
exp = "test%E3%81%82.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));

url = "ftp://example.com/test%E3%81%82.txt";
exp = "test%E3%81%82.txt";
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
}

public void test_decodeUrl_null() throws Exception {
Expand Down

0 comments on commit 162081c

Please sign in to comment.