From 162081c2e2937349af58fe010d05b37678a689e0 Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Thu, 9 Jan 2025 18:02:12 +0900 Subject: [PATCH] fix #2866 Prevent URL decoding of filenames for specific schemes. --- .../crawler/transformer/FessTransformer.java | 4 +++- .../transformer/FessFileTransformerTest.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codelibs/fess/crawler/transformer/FessTransformer.java b/src/main/java/org/codelibs/fess/crawler/transformer/FessTransformer.java index fa6e1fcfa..4aeeb4c5a 100644 --- a/src/main/java/org/codelibs/fess/crawler/transformer/FessTransformer.java +++ b/src/main/java/org/codelibs/fess/crawler/transformer/FessTransformer.java @@ -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) { diff --git a/src/test/java/org/codelibs/fess/crawler/transformer/FessFileTransformerTest.java b/src/test/java/org/codelibs/fess/crawler/transformer/FessFileTransformerTest.java index a482a36b9..da1044aee 100644 --- a/src/test/java/org/codelibs/fess/crawler/transformer/FessFileTransformerTest.java +++ b/src/test/java/org/codelibs/fess/crawler/transformer/FessFileTransformerTest.java @@ -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 {