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

[UNDERTOW-1748] add comment line to predicates #1642

Merged
merged 1 commit into from
Oct 4, 2024
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 @@ -653,6 +653,23 @@ public static Deque<Token> tokenize(final String string) {
}
} else {
switch (c) {
case '#':
final Token previous = ret.peekLast();
if(previous == null ||(previous != null && previous.getToken().equals("\n"))) {
//its either first line ever or new line
pos++;
while (pos < string.length()) {
char skip = string.charAt(pos);
if(skip == '\n' || skip == '\r') {
break;
}
pos++;
}
break;
} else {
current.append(c);
break;
}
case ' ':
case '\t': {
if (current.length() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public void testPredicateContextVariable() {

@Test
public void testRegularExpressionsWithPredicateContext() {
Predicate predicate = PredicateParser.parse("regex[pattern=a* , value=%{RELATIVE_PATH}] and equals[{$0, aaa}]", PredicateParsingTestCase.class.getClassLoader());
Predicate predicate = PredicateParser.parse("#Im Not related\nregex[pattern=#a* , value=%{RELATIVE_PATH}] and equals[{$0, #aaa}]", PredicateParsingTestCase.class.getClassLoader());
HttpServerExchange e = new HttpServerExchange(null);
e.putAttachment(Predicate.PREDICATE_CONTEXT, new HashMap<String, Object>());
e.setRelativePath("aaab");
e.setRelativePath("#aaab");
Assert.assertTrue(predicate.resolve(e));
e.setRelativePath("aaaab");
e.setRelativePath("#aaaab");
Assert.assertFalse(predicate.resolve(e));

predicate = PredicateParser.parse("regex[pattern='a(b*)a*' , value=%{RELATIVE_PATH}] and equals[$1, bb]", PredicateParsingTestCase.class.getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void testRewrite() throws IOException {
"regex('(.*).css') -> {rewrite['${1}.xcss'];set(attribute='%{o,chained}', value=true)} \n" +
"regex('(.*).redirect$') -> redirect['${1}.redirected']\n\n\n\n\n" +
"set[attribute='%{o,someHeader}', value=always]\n" +
"#ImJust a Comment\n"+
"path-template('/foo/{bar}/{f}') -> set[attribute='%{o,template}', value='${bar}']\r\n" +
"path-template('/bar->foo') -> redirect(/);" +
"regex('(.*).css') -> set[attribute='%{o,css}', value='true'] else set[attribute='%{o,css}', value='false']; " +
Expand Down
Loading