You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fs...@apache.org on 2016/02/15 22:08:27 UTC
svn commit: r1730612 - in /tomcat/trunk:
java/org/apache/catalina/valves/rewrite/Substitution.java
test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
webapps/docs/changelog.xml
Author: fschumacher
Date: Mon Feb 15 21:08:26 2016
New Revision: 1730612
URL: http://svn.apache.org/viewvc?rev=1730612&view=rev
Log:
Make checking for var and map replacement in RewriteValve a bit stricter and
correct detection of colon in var replacement.
Modified:
tomcat/trunk/java/org/apache/catalina/valves/rewrite/Substitution.java
tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/valves/rewrite/Substitution.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/rewrite/Substitution.java?rev=1730612&r1=1730611&r2=1730612&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/rewrite/Substitution.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/rewrite/Substitution.java Mon Feb 15 21:08:26 2016
@@ -149,7 +149,7 @@ public class Substitution {
newElement.n = Character.digit(sub.charAt(dollarPos + 1), 10);
pos = dollarPos + 2;
elements.add(newElement);
- } else {
+ } else if (sub.charAt(dollarPos + 1) == '{') {
// $: map lookup as ${mapname:key|default}
MapElement newElement = new MapElement();
int open = sub.indexOf('{', dollarPos);
@@ -177,6 +177,8 @@ public class Substitution {
}
pos = close + 1;
elements.add(newElement);
+ } else {
+ throw new IllegalArgumentException(sub + ": missing digit or curly brace.");
}
} else {
// %: back reference to condition or server variable
@@ -196,7 +198,7 @@ public class Substitution {
newElement.n = Character.digit(sub.charAt(percentPos + 1), 10);
pos = percentPos + 2;
elements.add(newElement);
- } else {
+ } else if (sub.charAt(percentPos + 1) == '{') {
// %: server variable as %{variable}
SubstitutionElement newElement = null;
int open = sub.indexOf('{', percentPos);
@@ -205,10 +207,7 @@ public class Substitution {
if (!(-1 < open && open < close)) {
throw new IllegalArgumentException(sub);
}
- if (colon > -1) {
- if (!(open < colon && colon < close)) {
- throw new IllegalArgumentException(sub);
- }
+ if (colon > -1 && open < colon && colon < close) {
String type = sub.substring(open + 1, colon);
if (type.equals("ENV")) {
newElement = new ServerVariableEnvElement();
@@ -228,6 +227,8 @@ public class Substitution {
}
pos = close + 1;
elements.add(newElement);
+ } else {
+ throw new IllegalArgumentException(sub + ": missing digit or curly brace.");
}
}
}
Modified: tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java?rev=1730612&r1=1730611&r2=1730612&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java (original)
+++ tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java Mon Feb 15 21:08:26 2016
@@ -65,6 +65,43 @@ public class TestRewriteValve extends To
"RewriteRule /b/(.*).html$ /c/${mapa:$1|dd}", "/b/x.html", "/c/dd");
}
+ @Test
+ public void testRewriteServerVar() throws Exception {
+ doTestRewrite("RewriteRule /b/(.*).html$ /c%{SERVLET_PATH}", "/b/x.html", "/c/b/x.html");
+ }
+
+ @Test
+ public void testRewriteEnvVarAndServerVar() throws Exception {
+ System.setProperty("some_variable", "something");
+ doTestRewrite("RewriteRule /b/(.*).html$ /c/%{ENV:some_variable}%{SERVLET_PATH}", "/b/x.html", "/c/something/b/x.html");
+ }
+
+ @Test
+ public void testRewriteServerVarAndEnvVar() throws Exception {
+ System.setProperty("some_variable", "something");
+ doTestRewrite("RewriteRule /b/(.*).html$ /c%{SERVLET_PATH}/%{ENV:some_variable}", "/b/x.html", "/c/b/x.html/something");
+ }
+
+ @Test
+ public void testRewriteMissingCurlyBraceOnVar() throws Exception {
+ try {
+ doTestRewrite("RewriteRule /b/(.*).html$ /c%_{SERVLET_PATH}", "/b/x.html", "/c");
+ Assert.fail("IAE expected.");
+ } catch (java.lang.IllegalArgumentException e) {
+ // excpected as %_{ is invalid
+ }
+ }
+
+ @Test
+ public void testRewriteMissingCurlyBraceOnMapper() throws Exception {
+ try {
+ doTestRewrite("RewriteRule /b/(.*).html$ /c$_{SERVLET_PATH}", "/b/x.html", "/c");
+ Assert.fail("IAE expected.");
+ } catch (java.lang.IllegalArgumentException e) {
+ // excpected as $_{ is invalid
+ }
+ }
+
private void doTestRewrite(String config, String request, String expectedURI) throws Exception {
Tomcat tomcat = getTomcatInstance();
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1730612&r1=1730611&r2=1730612&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Feb 15 21:08:26 2016
@@ -76,6 +76,10 @@
<add>
Add JASPIC (JSR-196) support. (markt)
</add>
+ <add>
+ Make checking for var and map replacement in RewriteValve a bit stricter and
+ correct detection of colon in var replacement. (fschumacher)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org