Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that all filter parts have been used when running out of input string #1142

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,27 @@ public String filter(final String path) {
return path;
}
previousIndex += filter[filterIndex].length();

filterIndex++;
} else {
// skip to next filter part
filterIndex++;

// locate next slash
final int nextIndex = path.indexOf('/', previousIndex);
if (nextIndex != -1) {
previousIndex = nextIndex;
} else {
// out of string, did we match against all the filter elements already?
if(filterIndex < filter.length) {
return path;
}

previousIndex = path.length();

break;
}
}
filterIndex++;
} while (filterIndex < filter.length);

if (previousIndex == path.length()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,15 @@ public void testIgnoresIncorrectExpression2() {
assertThat(path).isSameAs(result);
}

@Test
public void testPathEndsAtSubstitute() {
final String path = "/profile/123456789";
final String expr = "/profile/{id}/info";

final PathFilter regexpPathUriFilter = new DefaultPathFilter("XXX", expr);

final String result = regexpPathUriFilter.filter(path);
assertThat(result).isEqualTo(path);
}

}