fix #2622 check if url starts with http on filename extraction
This commit is contained in:
parent
4d07249b81
commit
4f541e5b1f
2 changed files with 19 additions and 8 deletions
|
@ -175,15 +175,18 @@ public interface FessTransformer {
|
|||
return StringUtil.EMPTY;
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
String u = url;
|
||||
int idx = u.lastIndexOf('?');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
}
|
||||
if (u.startsWith("https:") || u.startsWith("http:")) {
|
||||
idx = u.lastIndexOf('?');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
}
|
||||
|
||||
idx = u.lastIndexOf('#');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
idx = u.lastIndexOf('#');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
}
|
||||
}
|
||||
u = decodeUrlAsName(u, u.startsWith("file:"));
|
||||
idx = u.lastIndexOf('/');
|
||||
|
|
|
@ -69,7 +69,7 @@ public class FessFileTransformerTest extends UnitFessTestCase {
|
|||
String url, exp;
|
||||
final FessFileTransformer transformer = createInstance();
|
||||
|
||||
url = "http://example.com/" + encodeUrl("#") + "/@@bar/index.html#fragment?foo=bar";
|
||||
url = "https://example.com/" + encodeUrl("#") + "/@@bar/index.html#fragment?foo=bar";
|
||||
exp = "index.html";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
|
||||
|
@ -84,6 +84,14 @@ public class FessFileTransformerTest extends UnitFessTestCase {
|
|||
url = "file://example.com/test%20+%2B.txt";
|
||||
exp = "test ++.txt";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
|
||||
url = "file://example.com/test#.txt";
|
||||
exp = "test#.txt";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
|
||||
url = "smb://example.com/test?.txt";
|
||||
exp = "test?.txt";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
}
|
||||
|
||||
public void test_decodeUrl_null() throws Exception {
|
||||
|
|
Loading…
Add table
Reference in a new issue