knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject knox git commit: KNOX-791 - XML attribute special character fix and unit test (Sandeep More via Sumit Gupta)
Date Fri, 16 Dec 2016 16:03:47 GMT
Repository: knox
Updated Branches:
  refs/heads/master de34419d4 -> 7287e3559


KNOX-791 - XML attribute special character fix and unit test (Sandeep More via Sumit Gupta)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/7287e355
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/7287e355
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/7287e355

Branch: refs/heads/master
Commit: 7287e35597fffee78cfa2d3de4297c59873b6c6a
Parents: de34419
Author: Sumit Gupta <sumit@apache.org>
Authored: Fri Dec 16 11:03:25 2016 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Fri Dec 16 11:03:25 2016 -0500

----------------------------------------------------------------------
 .../rewrite/impl/html/HtmlFilterReaderBase.java |  6 ++-
 .../api/UrlRewriteServletFilterTest.java        | 42 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/7287e355/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
index f9d11cf..6839e44 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
@@ -171,7 +171,11 @@ public abstract class HtmlFilterReaderBase extends Reader implements
UrlRewriteF
     writer.write( " " );
     writer.write( attribute.getName() );
     if(attribute.hasValue()) {
-      String inputValue = attribute.getValue();
+      /*
+       * non decoded value, return the raw value of the attribute as it appears
+       * in the source document, without decoding, see KNOX-791.
+       */
+      String inputValue = attribute.getValueSegment().toString();
       String outputValue = inputValue;
       try {
         Level tag = stack.peek();

http://git-wip-us.apache.org/repos/asf/knox/blob/7287e355/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
index 8052c2b..d435ef7 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
@@ -806,6 +806,48 @@ public class UrlRewriteServletFilterTest {
 //    assertThat( the( content ), hasXPath( "//style/text()", equalTo( "@import \\\"http://0.0.0.0:0/stylesheets/pretty.css\\\";"
) ) );
     assertThat(content, anyOf( is(responseHtmlOne), is(responseHtmlTwo)));
   }
+  
+  /**
+   * See KNOX-791
+   * @since 0.11.0
+   * @throws Exception
+   */
+  @Test
+  public void testResponseHtmlAttributeEscaping() throws Exception {
+    final Map<String, String> initParams = new HashMap<String, String>();
+    initParams.put("response.body", "test-filter-4");
+    setUp(initParams);
+
+    final String responseHtml = "<!DOCTYPE html>\n" + "<html>\n" + "  <head>\n"
+        + "    <meta charset=\"UTF-8\">\n"
+        + "    <link rel=\"stylesheet\" href=\"pretty.css\">\n"
+        + "    <script escaped-data=\"&lt;&gt;\" src=\"script.js\"></script>\n"
+        + "  </head>\n" + "  <body>\n" + "  </body>\n" + "</html>";
+    final String rewrittenResponseHtml = "<!DOCTYPE html>\n" + "<html>\n"
+        + "  <head>\n" + "    <meta charset=\"UTF-8\">\n"
+        + "    <link rel=\"stylesheet\" href=\"http://someotherhost/stylesheets/pretty.css\">\n"
+        + "    <script escaped-data=\"&lt;&gt;\" src=\"script.js\"></script>\n"
+        + "  </head>\n" + "  <body>\n" + "  </body>\n" + "</html>";
+
+    // Setup the server side request/response interaction.
+    interaction.expect().method("GET")
+        .requestUrl("http://mock-host:42/test-output-path-1");
+    interaction.respond().contentType("application/html")
+        .content(responseHtml, Charset.forName("UTF-8")).status(200);
+    interactions.add(interaction);
+    request.setMethod("GET");
+    request.setURI("/test-input-path");
+    request.setHeader("Host", "mock-host:42");
+    request.setHeader("Content-Type", "application/html");
+
+    // Execute the request.
+    response = TestUtils.execute(server, request);
+
+    assertThat(response.getStatus(), is(200));
+    String content = response.getContent();
+    assertThat(content, is(rewrittenResponseHtml));
+  }
+  
 
   private static class SetupFilter implements Filter {
     @Override


Mime
View raw message