You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/29 14:39:02 UTC
[tomcat] branch master updated: Fix
https://bz.apache.org/bugzilla/show_bug.cgi?id=63608 -ve pattern
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 0449873 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63608 -ve pattern
0449873 is described below
commit 044987365a41167083d2c9d3b73a43ebfa2567b9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jul 29 15:38:05 2019 +0100
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63608 -ve pattern
Align the implementation of the negative match feature for patterns used
with the RewriteValve with the description in the documentation.
---
.../catalina/valves/rewrite/RewriteRule.java | 8 +++++++-
.../catalina/valves/rewrite/TestRewriteValve.java | 24 ++++++++++++++++++++++
webapps/docs/changelog.xml | 5 +++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/valves/rewrite/RewriteRule.java b/java/org/apache/catalina/valves/rewrite/RewriteRule.java
index 0bee31f..450877d 100644
--- a/java/org/apache/catalina/valves/rewrite/RewriteRule.java
+++ b/java/org/apache/catalina/valves/rewrite/RewriteRule.java
@@ -32,6 +32,7 @@ public class RewriteRule {
protected String patternString = null;
protected String substitutionString = null;
protected String flagsString = null;
+ protected boolean positive = true;
public void parse(Map<String, RewriteMap> maps) {
// Parse the substitution
@@ -42,6 +43,10 @@ public class RewriteRule {
substitution.setEscapeBackReferences(isEscapeBackReferences());
}
// Parse the pattern
+ if (patternString.startsWith("!")) {
+ positive = false;
+ patternString = patternString.substring(1);
+ }
int flags = 0;
if (isNocase()) {
flags |= Pattern.CASE_INSENSITIVE;
@@ -92,7 +97,8 @@ public class RewriteRule {
this.pattern.set(pattern);
}
Matcher matcher = pattern.matcher(url);
- if (!matcher.matches()) {
+ // Use XOR
+ if (positive ^ matcher.matches()) {
// Evaluation done
return null;
}
diff --git a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
index 464f3b3..8e2e3f2 100644
--- a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
+++ b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
@@ -582,6 +582,30 @@ public class TestRewriteValve extends TomcatBaseTest {
}
+ @Test
+ public void testNegativePattern01() throws Exception {
+ doTestRewrite("RewriteRule !^/b/.* /c/", "/b", "/c/");
+ }
+
+
+ @Test
+ public void testNegativePattern02() throws Exception {
+ doTestRewrite("RewriteRule !^/b/.* /c/", "/d/e/f", "/c/");
+ }
+
+
+ @Test
+ public void testNegativePattern03() throws Exception {
+ doTestRewrite("RewriteRule !^/c/.* /b/", "/c/", "/c/");
+ }
+
+
+ @Test
+ public void testNegativePattern04() throws Exception {
+ doTestRewrite("RewriteRule !^/c/.* /b/", "/c/d", "/c/d");
+ }
+
+
private void doTestRewrite(String config, String request, String expectedURI) throws Exception {
doTestRewrite(config, request, expectedURI, null);
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f96bdfe..b70fc1c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -69,6 +69,11 @@
reject them with a 400 response rather than triggering an internal error
that results in a 500 response. (markt)
</fix>
+ <fix>
+ <bug>63608</bug>: Align the implementation of the negative match feature
+ for patterns used with the <code>RewriteValve</code> with the
+ description in the documentation. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org