Skip to content

Commit

Permalink
Polishing contribution
Browse files Browse the repository at this point in the history
Closes gh-27623
  • Loading branch information
rstoyanchev committed Nov 9, 2021
1 parent b574396 commit c6ce65e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Expand Up @@ -405,17 +405,18 @@ else if (index1 == requestUri.length()) {
* </ul>
*/
private static String getSanitizedPath(final String path) {
if (path.length() == 0) {
int start = path.indexOf("//");
if (start == -1) {
return path;
}
char[] arr = path.toCharArray();
int slowIndex = 0;
for (int fastIndex = 1; fastIndex < arr.length; fastIndex++) {
if (arr[fastIndex] != '/' || arr[slowIndex] != '/') {
arr[++slowIndex] = arr[fastIndex];
char[] content = path.toCharArray();
int slowIndex = start;
for (int fastIndex = start + 1; fastIndex < content.length; fastIndex++) {
if (content[fastIndex] != '/' || content[slowIndex] != '/') {
content[++slowIndex] = content[fastIndex];
}
}
return new String(arr, 0, slowIndex + 1);
return new String(content, 0, slowIndex + 1);
}

/**
Expand Down
Expand Up @@ -232,12 +232,12 @@ void removeDuplicateSlashesInPath() {
request.setContextPath("/SPR-12372");
request.setPathInfo(null);
request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo//bar/");
request.setRequestURI("/SPR-12372/foo///bar/");

assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");

request.setServletPath("/foo/bar/");
request.setRequestURI("/SPR-12372/foo/bar//");
request.setRequestURI("////SPR-12372/foo/bar//");

assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/foo/bar/");

Expand Down

0 comments on commit c6ce65e

Please sign in to comment.