avoid to change an existing test case (ref: review on #1077)
This commit is contained in:
parent
9d354a3879
commit
1dfc509262
2 changed files with 28 additions and 8 deletions
|
@ -183,9 +183,18 @@ public interface FessTransformer {
|
|||
return StringUtil.EMPTY;
|
||||
}
|
||||
|
||||
String u = decodeUrlAsName(url, url.startsWith("file:"));
|
||||
String u = url;
|
||||
int idx = u.lastIndexOf('?');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
}
|
||||
|
||||
int idx = u.lastIndexOf('/');
|
||||
idx = u.lastIndexOf('#');
|
||||
if (idx >= 0) {
|
||||
u = u.substring(0, idx);
|
||||
}
|
||||
u = decodeUrlAsName(u, u.startsWith("file:"));
|
||||
idx = u.lastIndexOf('/');
|
||||
if (idx >= 0) {
|
||||
if (u.length() > idx + 1) {
|
||||
u = u.substring(idx + 1);
|
||||
|
@ -229,9 +238,7 @@ public interface FessTransformer {
|
|||
|
||||
final String escapedUrl = escapePlus ? url.replace("+", "%2B") : url;
|
||||
try {
|
||||
final URI u = new URI(escapedUrl);
|
||||
final URI uri = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), null, null);
|
||||
return URLDecoder.decode(uri.toString(), enc);
|
||||
return URLDecoder.decode(escapedUrl, enc);
|
||||
} catch (final Exception e) {
|
||||
return url;
|
||||
}
|
||||
|
@ -255,4 +262,4 @@ public interface FessTransformer {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,10 +61,23 @@ public class FessFileTransformerTest extends UnitFessTestCase {
|
|||
assertEquals(exp, transformer.decodeUrlAsName(url, true));
|
||||
|
||||
url = "http://example.com/foo/" + encodeUrl("#") + "/@@bar/index.html#fragment?foo=bar";
|
||||
exp = "http://example.com/foo/#/@@bar/index.html";
|
||||
exp = "http://example.com/foo/#/@@bar/index.html#fragment?foo=bar";
|
||||
assertEquals(exp, transformer.decodeUrlAsName(url, false));
|
||||
}
|
||||
|
||||
public void test_getFileName_ok() throws Exception {
|
||||
String url, exp;
|
||||
final FessFileTransformer transformer = createInstance();
|
||||
|
||||
url = "http://example.com/" + encodeUrl("#") + "/@@bar/index.html#fragment?foo=bar";
|
||||
exp = "index.html";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
|
||||
url = "http://example.com/" + encodeUrl("#") + "/@@folder/test.txt";
|
||||
exp = "test.txt";
|
||||
assertEquals(exp, transformer.getFileName(url, Constants.UTF_8));
|
||||
}
|
||||
|
||||
public void test_decodeUrl_null() throws Exception {
|
||||
final FessFileTransformer transformer = createInstance();
|
||||
assertNull(transformer.decodeUrlAsName(null, true));
|
||||
|
@ -220,7 +233,7 @@ public class FessFileTransformerTest extends UnitFessTestCase {
|
|||
assertEquals(exp, transformer.getSiteOnFile(url, "UTF-8"));
|
||||
|
||||
url = "file:///";
|
||||
exp = "/";
|
||||
exp = "///";
|
||||
assertEquals(exp, transformer.getSiteOnFile(url, "UTF-8"));
|
||||
|
||||
url = "file://///";
|
||||
|
|
Loading…
Add table
Reference in a new issue