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 f76d39093f Code clean-up. No functional change.
f76d39093f is described below
commit f76d39093f4d62619eaab5272924364f53fbdeef
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Mar 30 23:35:16 2023 +0100
Code clean-up. No functional change.
---
.../catalina/valves/rewrite/TestResolverSSL.java | 5 +-
.../catalina/valves/rewrite/TestRewriteValve.java | 220 +++++++++------------
.../catalina/valves/rewrite/TesterRewriteMapA.java | 2 +-
3 files changed, 98 insertions(+), 129 deletions(-)
diff --git a/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java
b/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java
index a1ac1f6a29..e54f49103e 100644
--- a/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java
+++ b/test/org/apache/catalina/valves/rewrite/TestResolverSSL.java
@@ -57,6 +57,7 @@ public class TestResolverSSL extends TomcatBaseTest {
Assert.assertTrue(res.toString().indexOf("OK") > 0);
}
+ //@formatter:off
// List from https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#envvars
private static final String[] keys = {
"HTTPS",
@@ -114,12 +115,12 @@ public class TestResolverSSL extends TomcatBaseTest {
"SSL_SRP_USER",
"SSL_SRP_USERINFO",
"SSL_TLS_SNI" };
+ //@formatter:on
public static class ResolverTestValve extends ValveBase {
@Override
- public void invoke(Request request, Response response)
- throws IOException, ServletException {
+ public void invoke(Request request, Response response) throws
IOException, ServletException {
PrintWriter writer = response.getWriter();
Resolver resolver = new ResolverImpl(request);
for (String key : keys) {
diff --git a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
index c6ecd486af..cf58cf05fb 100644
--- a/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
+++ b/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
@@ -121,26 +121,22 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testRewriteMap08() throws Exception {
- doTestRewrite("RewriteMap lc int:tolower\n" +
- "RewriteRule ^(.*) ${lc:$1}", "/C/AaA", "/c/aaa");
+ doTestRewrite("RewriteMap lc int:tolower\n" + "RewriteRule ^(.*)
${lc:$1}", "/C/AaA", "/c/aaa");
}
@Test
public void testRewriteMap09() throws Exception {
- doTestRewrite("RewriteMap lc int:toupper\n" +
- "RewriteRule ^(.*) ${lc:$1}", "/w/aAa", "/W/AAA");
+ doTestRewrite("RewriteMap lc int:toupper\n" + "RewriteRule ^(.*)
${lc:$1}", "/w/aAa", "/W/AAA");
}
@Test
public void testRewriteMap10() throws Exception {
- doTestRewrite("RewriteMap lc int:escape\n" +
- "RewriteRule ^(.*) ${lc:$1}", "/c/a%20aa", "/c/a%2520aa");
+ doTestRewrite("RewriteMap lc int:escape\n" + "RewriteRule ^(.*)
${lc:$1}", "/c/a%20aa", "/c/a%2520aa");
}
@Test
public void testRewriteMap11() throws Exception {
- doTestRewrite("RewriteMap lc int:unescape\n" +
- "RewriteRule ^(.*) ${lc:$1}", "/c/a%2520aa", "/c/a%20aa");
+ doTestRewrite("RewriteMap lc int:unescape\n" + "RewriteRule ^(.*)
${lc:$1}", "/c/a%2520aa", "/c/a%20aa");
}
@@ -153,86 +149,86 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testRewriteMap12() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html",
"/c/aa");
}
@Test
public void testRewriteMap13() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1|dd}", "/b/x.html",
"/c/dd");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1|dd}", "/b/x.html",
"/c/dd");
}
// BZ 62667
@Test
public void testRewriteMap14() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1|d$1d}", "/b/x.html",
"/c/dxd");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1|d$1d}", "/b/x.html",
"/c/dxd");
}
@Test
public void testRewriteMap15() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:a$1|dd}", "/b/a.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:a$1|dd}", "/b/a.html",
"/c/aaaa");
}
@Test
public void testRewriteMap16() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/.* /c/${mapb:a}", "/b/a.html", "/c/aa");
+ "RewriteRule /b/.* /c/${mapb:a}", "/b/a.html", "/c/aa");
}
@Test
public void testRewriteMap17() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa");
+ "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html",
"/c/aaaa");
}
@Test
public void testRewriteMap18() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt\n" +
- "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html", "/c/aaaa");
+ "RewriteRule /b/.* /c/${mapb:${mapb:a}}", "/b/a.html",
"/c/aaaa");
}
@Test(expected = IllegalArgumentException.class)
public void testRewriteMap19() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt first\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
}
@Test(expected = IllegalArgumentException.class)
public void testRewriteMap20() throws Exception {
doTestRewrite("RewriteMap mapb txt:" + getTestConfDirectory() +
"TesterRewriteMapB.txt first second\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
}
@Test
public void testRewriteMap21() throws Exception {
doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() +
"TesterRewriteMapC.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html", "/c/aa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/a.html",
"/c/aa");
}
- //This test should succeed 50% of the runs as it depends on a random choice
+ // This test should succeed 50% of the runs as it depends on a random
choice
public void testRewriteMap22() throws Exception {
doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() +
"TesterRewriteMapC.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/b.html", "/c/bb");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/b.html",
"/c/bb");
}
@Test
public void testRewriteMap23() throws Exception {
doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() +
"TesterRewriteMapC.txt\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
}
@Test(expected = IllegalArgumentException.class)
public void testRewriteMap24() throws Exception {
doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() +
"TesterRewriteMapC.txt first\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
}
@Test(expected = IllegalArgumentException.class)
public void testRewriteMap25() throws Exception {
doTestRewrite("RewriteMap mapb rnd:" + getTestConfDirectory() +
"TesterRewriteMapC.txt first second\n" +
- "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
+ "RewriteRule /b/(.*).html$ /c/${mapb:$1}", "/b/aa.html",
"/c/aaaa");
}
@Test
@@ -243,15 +239,15 @@ public class TestRewriteValve extends TomcatBaseTest {
@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");
+ 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");
+ doTestRewrite("RewriteRule /b/(.*).html$
/c%{SERVLET_PATH}/%{ENV:some_variable}", "/b/x.html",
+ "/c/b/x.html/something");
}
@Test
@@ -276,8 +272,8 @@ public class TestRewriteValve extends TomcatBaseTest {
// https://bz.apache.org/bugzilla/show_bug.cgi?id=60013
public void testRewriteWithEncoding02() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*)$ /c/?param=$1 [L]",
- "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c/",
"param=\u5728\u7EBF\u6D4B\u8BD5");
+ doTestRewrite("RewriteRule ^/b/(.*)$ /c/?param=$1 [L]",
"/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c/",
+ "param=\u5728\u7EBF\u6D4B\u8BD5");
}
@Test
@@ -288,8 +284,7 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testNonAsciiPathRedirect() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*) /c/$1 [R]",
- "/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95",
+ doTestRewrite("RewriteRule ^/b/(.*) /c/$1 [R]",
"/b/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95",
"/c/%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95");
}
@@ -310,32 +305,28 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testNonAsciiQueryString() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*) /c?$1",
- "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95",
- "/c", "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95");
+ doTestRewrite("RewriteRule ^/b/(.*) /c?$1",
"/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c",
+ "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95");
}
@Test
public void testNonAsciiQueryStringAndPath() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2",
- "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95",
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2",
"/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95",
"/c/%E5%9C%A8%E7%BA%BF", "id=%E6%B5%8B%E8%AF%95");
}
@Test
public void testNonAsciiQueryStringAndRedirect() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*) /c?$1 [R]",
- "/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95",
- "/c", "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95");
+ doTestRewrite("RewriteRule ^/b/(.*) /c?$1 [R]",
"/b/id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95", "/c",
+ "id=%E5%9C%A8%E7%BA%BF%E6%B5%8B%E8%AF%95");
}
@Test
public void testNonAsciiQueryStringAndPathAndRedirect() throws Exception {
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2 [R]",
- "/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95",
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/$1?$2 [R]",
"/b/%E5%9C%A8%E7%BA%BF/id=%E6%B5%8B%E8%AF%95",
"/c/%E5%9C%A8%E7%BA%BF", "id=%E6%B5%8B%E8%AF%95");
}
@@ -352,8 +343,7 @@ public class TestRewriteValve extends TomcatBaseTest {
public void testNonAsciiQueryStringAndPathAndRedirectWithB() throws
Exception {
// Note the double encoding of the result (httpd produces the same
result)
doTestRewrite("RewriteRule ^/b/(.*)/(.*)/id=(.*)
/c/$1?filename=$2&id=$3 [B,R]",
- "/b/%E5%9C%A8%E7%BA%BF/file01/id=%E6%B5%8B%E8%AF%95",
- "/c/%25E5%259C%25A8%25E7%25BA%25BF",
+ "/b/%E5%9C%A8%E7%BA%BF/file01/id=%E6%B5%8B%E8%AF%95",
"/c/%25E5%259C%25A8%25E7%25BA%25BF",
"filename=file01&id=%25E6%25B5%258B%25E8%25AF%2595");
}
@@ -361,32 +351,32 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testUtf8WithBothQsFlagsNone() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1",
"id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1",
+ "id=%C2%A1");
}
@Test
public void testUtf8WithBothQsFlagsB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1",
"id=%25C2%25A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1");
}
@Test
public void testUtf8WithBothQsFlagsR() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1",
"id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%C2%A1", "id=%C2%A1");
}
@Test
public void testUtf8WithBothQsFlagsRB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1",
"id=%25C2%25A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1");
}
@@ -395,8 +385,7 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@@ -405,35 +394,31 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@Test
public void testUtf8WithBothQsFlagsBQSA() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1",
- "id=%25C2%25A1&di=%C2%AE");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B,QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1&di=%C2%AE");
}
@Test
public void testUtf8WithBothQsFlagsRQSA() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1",
- "id=%C2%A1&di=%C2%AE");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%C2%A1", "id=%C2%A1&di=%C2%AE");
}
@Test
public void testUtf8WithBothQsFlagsRBQSA() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%25C2%25A1",
- "id=%25C2%25A1&di=%C2%AE");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1&di=%C2%AE");
}
@@ -442,8 +427,7 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE,QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@@ -452,40 +436,37 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE,QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@Test
public void testUtf8WithOriginalQsFlagsNone() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1",
- "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1",
"/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
}
@Test
public void testUtf8WithOriginalQsFlagsB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [B]",
- "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [B]",
"/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1",
+ "id=%C2%A1");
}
@Test
public void testUtf8WithOriginalQsFlagsR() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R]",
- "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R]",
"/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
}
@Test
public void testUtf8WithOriginalQsFlagsRB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B]",
- "/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B]",
"/b/%C2%A1?id=%C2%A1", "/c/%C2%A1%25C2%25A1",
+ "id=%C2%A1");
}
@@ -494,8 +475,7 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]",
- "/b/%C2%A1?id=%C2%A1", null);
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]",
"/b/%C2%A1?id=%C2%A1", null);
}
@@ -504,49 +484,47 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]",
- "/b/%C2%A1?id=%C2%A1", null);
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]",
"/b/%C2%A1?id=%C2%A1", null);
}
@Test
public void testUtf8WithRewriteQsFlagsNone() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2",
- "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2",
"/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1",
+ "id=%C2%A1");
}
@Test
public void testUtf8WithRewriteQsFlagsB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]",
- "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [B]",
"/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1",
+ "id=%25C2%25A1");
}
@Test
public void testUtf8WithRewriteQsFlagsR() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]",
- "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1", "id=%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R]",
"/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1",
+ "id=%C2%A1");
}
@Test
public void testUtf8WithBothQsFlagsQSA() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/%C2%A1%C2%A1",
- "id=%C2%A1&di=%C2%AE");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]",
"/b/%C2%A1/id=%C2%A1?di=%C2%AE",
+ "/c/%C2%A1%C2%A1", "id=%C2%A1&di=%C2%AE");
}
@Test
public void testUtf8WithRewriteQsFlagsRB() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]",
- "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1", "id=%25C2%25A1");
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B]",
"/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%25C2%25A1",
+ "id=%25C2%25A1");
}
@@ -555,8 +533,7 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
- "/b/%C2%A1/id=%C2%A1", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
"/b/%C2%A1/id=%C2%A1", null);
}
@@ -565,16 +542,14 @@ public class TestRewriteValve extends TomcatBaseTest {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
- "/b/%C2%A1/id=%C2%A1", null);
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
"/b/%C2%A1/id=%C2%A1", null);
}
@Test
public void testUtf8WithRewriteQsFlagsQSA() throws Exception {
// Note %C2%A1 == \u00A1
- doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]",
- "/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1",
+ doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [QSA]",
"/b/%C2%A1/id=%C2%A1", "/c/%C2%A1%C2%A1",
"id=%C2%A1");
}
@@ -628,9 +603,8 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testFlagsNC() throws Exception {
// https://bz.apache.org/bugzilla/show_bug.cgi?id=60116
- doTestRewrite("RewriteCond %{QUERY_STRING} a=([a-z]*) [NC]\n"
- + "RewriteRule .* - [E=X-Test:%1]",
- "/c?a=aAa", "/c", null, "aAa");
+ doTestRewrite("RewriteCond %{QUERY_STRING} a=([a-z]*) [NC]\n" +
"RewriteRule .* - [E=X-Test:%1]", "/c?a=aAa",
+ "/c", null, "aAa");
}
@@ -638,33 +612,29 @@ public class TestRewriteValve extends TomcatBaseTest {
public void testHostRewrite() throws Exception {
// Based on report from users list that ':' was encoded and breaking
// the redirect
- doTestRewrite("RewriteRule ^/b(.*)
http://%{HTTP_HOST}:%{SERVER_PORT}/a$1 [R]",
- "/b/%255A", "/a/%255A");
+ doTestRewrite("RewriteRule ^/b(.*)
http://%{HTTP_HOST}:%{SERVER_PORT}/a$1 [R]", "/b/%255A", "/a/%255A");
}
@Test
public void testDefaultRedirect() throws Exception {
- doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a",
"/redirect/to/b",
- 302);
+ doTestRedirect("RewriteRule ^/from/a$ /to/b [R]", "/redirect/from/a",
"/redirect/to/b", 302);
}
@Test
public void testTempRedirect() throws Exception {
- doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]",
"/redirect/from/a", "/redirect/to/b",
- 302);
+ doTestRedirect("RewriteRule ^/from/a$ /to/b [R=temp]",
"/redirect/from/a", "/redirect/to/b", 302);
}
@Test
public void testPermanentRedirect() throws Exception {
- // Disable the following of redirects for this test only
+ // Disable the following of redirects for this test only
boolean originalValue = HttpURLConnection.getFollowRedirects();
HttpURLConnection.setFollowRedirects(false);
try {
- doTestRedirect("RewriteRule ^/from/a$ /to/b [R=permanent]",
"/redirect/from/a", "/redirect/to/b",
- 301);
+ doTestRedirect("RewriteRule ^/from/a$ /to/b [R=permanent]",
"/redirect/from/a", "/redirect/to/b", 301);
} finally {
HttpURLConnection.setFollowRedirects(originalValue);
}
@@ -673,12 +643,11 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void testSeeotherRedirect() throws Exception {
- // Disable the following of redirects for this test only
+ // Disable the following of redirects for this test only
boolean originalValue = HttpURLConnection.getFollowRedirects();
HttpURLConnection.setFollowRedirects(false);
try {
- doTestRedirect("RewriteRule ^/from/a$ /to/b [R=seeother]",
"/redirect/from/a", "/redirect/to/b",
- 303);
+ doTestRedirect("RewriteRule ^/from/a$ /to/b [R=seeother]",
"/redirect/from/a", "/redirect/to/b", 303);
} finally {
HttpURLConnection.setFollowRedirects(originalValue);
}
@@ -687,12 +656,11 @@ public class TestRewriteValve extends TomcatBaseTest {
@Test
public void test307Redirect() throws Exception {
- // Disable the following of redirects for this test only
+ // Disable the following of redirects for this test only
boolean originalValue = HttpURLConnection.getFollowRedirects();
HttpURLConnection.setFollowRedirects(false);
try {
- doTestRedirect("RewriteRule ^/from/a$ /to/b [R=307]",
"/redirect/from/a", "/redirect/to/b",
- 307);
+ doTestRedirect("RewriteRule ^/from/a$ /to/b [R=307]",
"/redirect/from/a", "/redirect/to/b", 307);
} finally {
HttpURLConnection.setFollowRedirects(originalValue);
}
@@ -749,14 +717,14 @@ public class TestRewriteValve extends TomcatBaseTest {
}
- private void doTestRewrite(String config, String request, String
expectedURI,
- String expectedQueryString) throws Exception {
+ private void doTestRewrite(String config, String request, String
expectedURI, String expectedQueryString)
+ throws Exception {
doTestRewrite(config, request, expectedURI, expectedQueryString, null);
}
- private void doTestRewrite(String config, String request, String
expectedURI,
- String expectedQueryString, String expectedAttributeValue) throws
Exception {
+ private void doTestRewrite(String config, String request, String
expectedURI, String expectedQueryString,
+ String expectedAttributeValue) throws Exception {
Tomcat tomcat = getTomcatInstance();
@@ -803,8 +771,8 @@ public class TestRewriteValve extends TomcatBaseTest {
}
}
- private void doTestRedirect(String config, String request, String
expectedURI,
- int expectedStatusCode) throws Exception {
+ private void doTestRedirect(String config, String request, String
expectedURI, int expectedStatusCode)
+ throws Exception {
Tomcat tomcat = getTomcatInstance();
@@ -824,8 +792,8 @@ public class TestRewriteValve extends TomcatBaseTest {
ByteChunk res = new ByteChunk();
Map<String, List<String>> resHead = new HashMap<>();
- int rc = methodUrl("http://localhost:" + getPort() + request, res,
- DEFAULT_CLIENT_TIMEOUT_MS, null, resHead, "GET", false);
+ int rc = methodUrl("http://localhost:" + getPort() + request, res,
DEFAULT_CLIENT_TIMEOUT_MS, null, resHead,
+ "GET", false);
res.setCharset(StandardCharsets.UTF_8);
if (expectedURI == null) {
@@ -866,10 +834,10 @@ public class TestRewriteValve extends TomcatBaseTest {
Map<String, List<String>> reqHead = new HashMap<>();
reqHead.put("cookie", Arrays.asList("test=data"));
ByteChunk res = new ByteChunk();
- int rc = methodUrl("http://localhost:" + getPort() +
"/source/cookieTest", res,
- DEFAULT_CLIENT_TIMEOUT_MS, reqHead, null, "GET", false);
+ int rc = methodUrl("http://localhost:" + getPort() +
"/source/cookieTest", res, DEFAULT_CLIENT_TIMEOUT_MS,
+ reqHead, null, "GET", false);
- Assert.assertEquals(HttpServletResponse.SC_OK , rc);
+ Assert.assertEquals(HttpServletResponse.SC_OK, rc);
res.setCharset(StandardCharsets.UTF_8);
Assert.assertEquals("PASS", res.toString());
diff --git a/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java
b/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java
index 4be8fd7fe9..3c4c7b6502 100644
--- a/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java
+++ b/test/org/apache/catalina/valves/rewrite/TesterRewriteMapA.java
@@ -21,7 +21,7 @@ import java.util.Map;
public class TesterRewriteMapA implements RewriteMap {
- private static final Map<String,String> map = new HashMap<>();
+ private static final Map<String, String> map = new HashMap<>();
static {
map.put("a", "aa");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]