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:40:39 UTC

[tomcat] branch 8.5.x 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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 802d30b  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63608 -ve pattern
802d30b is described below

commit 802d30b9c66fc759f819d78d023341f35012df16
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 f93082f..dbca095 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -72,6 +72,11 @@
       <fix>
         Correct version information in <code>X-Powered-By</code> header. (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