Fix URL normalization when replacing /./ with /
Previously, a regular expression of /./ was used to replace /./ with /. The '.'' in the expression matches any single character so the replacement was more broadly applicable than it should have been. For example, /a/ would be replaced with /. This commit uses Pattern.LITERAL to compile the regular expression from the CURRENT_DIR (/./) contant. This allows the constant to be used to check for occurances of /./ in the string before attempting replacement, while also ensuring that the '.' is treated literally. Closes gh-17341
This commit is contained in:
@@ -51,7 +51,7 @@ public class Handler extends URLStreamHandler {
|
||||
|
||||
private static final String CURRENT_DIR = "/./";
|
||||
|
||||
private static final Pattern CURRENT_DIR_PATTERN = Pattern.compile(CURRENT_DIR);
|
||||
private static final Pattern CURRENT_DIR_PATTERN = Pattern.compile(CURRENT_DIR, Pattern.LITERAL);
|
||||
|
||||
private static final String PARENT_DIR = "/../";
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public class HandlerTests {
|
||||
@Test
|
||||
public void urlWithSpecReferencingParentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"../folderB/b.xsd");
|
||||
"../folderB/c/d/e.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +142,7 @@ public class HandlerTests {
|
||||
@Test
|
||||
public void urlWithSpecReferencingCurrentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"./folderB/./b.xsd");
|
||||
"./folderB/c/d/e.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user