From 6fb751e2163f3293f4d6492c07135e4c8a091b2b Mon Sep 17 00:00:00 2001 From: Michael Gorovoy Date: Mon, 15 Aug 2011 12:24:07 -0400 Subject: [PATCH] 354397 RewriteRegexRule handles special characters in regex group --- VERSION.txt | 1 + .../org/eclipse/jetty/rewrite/handler/RewriteRegexRule.java | 4 ++-- .../eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index a28985fad5f..26a626d79f3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -17,6 +17,7 @@ jetty-7.5.0-SNAPSHOT + 353862 Improve performance of QuotedStringTokenizer.quote() + 354014 Content-Length is passed to wrapped response in GZipFilter + 354204 Charset encodings property file not used + + 354397 RewriteRegexRule handles special characters in regex group + 354466 Typo in example config of jetty-plus.xml jetty-7.4.4.v20110707 July 7th 2011 diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRule.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRule.java index f606e8ec695..ce5700155f0 100644 --- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRule.java +++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRule.java @@ -56,7 +56,7 @@ public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI target=_replacement; for (int g=1;g<=matcher.groupCount();g++) { - String group = matcher.group(g); + String group = Matcher.quoteReplacement(matcher.group(g)); target=target.replaceAll("\\$"+g,group); } @@ -73,7 +73,7 @@ public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI String uri=_replacement; for (int g=1;g<=matcher.groupCount();g++) { - String group = matcher.group(g); + String group = Matcher.quoteReplacement(matcher.group(g)); uri=uri.replaceAll("\\$"+g,group); } request.setRequestURI(uri); diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java index 7d05946d1e0..35bb5f4ba0a 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java @@ -26,6 +26,8 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase {"/foo/bar",".*","/replace","/replace"}, {"/foo/bar","/xxx.*","/replace",null}, {"/foo/bar","/(.*)/(.*)","/$2/$1/xxx","/bar/foo/xxx"}, + {"/foo/$bar",".*","/$replace","/$replace"}, + {"/foo/$bar","/foo/(.*)","/$1/replace","/$bar/replace"}, }; private RewriteRegexRule _rule;