knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: KNOX-623: Gateway provider rewriter doesn't support boolean attributes in HTML.
Date Mon, 16 Nov 2015 15:29:48 GMT
Repository: knox
Updated Branches:
  refs/heads/master 4124b556b -> e7d7516b0


KNOX-623: Gateway provider rewriter doesn't support boolean attributes in HTML.


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

Branch: refs/heads/master
Commit: e7d7516b0e25e6b4e1a3c1598b5cd411f2f84504
Parents: 4124b55
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Mon Nov 16 10:29:36 2015 -0500
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Mon Nov 16 10:29:36 2015 -0500

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../rewrite/impl/html/HtmlFilterReaderBase.java | 32 +++++++++++---------
 .../impl/html/HtmlFilterReaderBaseTest.java     | 19 ++++++++++++
 3 files changed, 37 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/e7d7516b/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 85ef05f..466bd46 100644
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-614] - Incorrect URI template expansion with {**} query params #fragments
     * [KNOX-616] - XmlUrlRewriteStreamFilter unscapes escaped special characters
     * [KNOX-394] - Request and response URLs must be parsed as literals not templates
+    * [KNOX-623] - Gateway provider rewriter doesn't support boolean attributes in HTML.
 
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.6.0

http://git-wip-us.apache.org/repos/asf/knox/blob/e7d7516b/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 e2cf9be..75a27d6 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,23 +171,25 @@ public abstract class HtmlFilterReaderBase extends Reader implements
UrlRewriteF
   }
 
   private void processAttribute( Attribute attribute ) {
-    String inputValue = attribute.getValue();
-    String outputValue = inputValue;
-    try {
-      Level tag = stack.peek();
-      outputValue = filterAttribute( tag.getQName(), tag.getQName( attribute.getName() ),
inputValue, null );
-      if( outputValue == null ) {
-        outputValue = inputValue;
-      }
-    } catch ( Exception e ) {
-      LOG.failedToFilterAttribute( attribute.getName(), e );
-    }
     writer.write( " " );
     writer.write( attribute.getName() );
-    writer.write( "=" );
-    writer.write( attribute.getQuoteChar() );
-    writer.write( outputValue );
-    writer.write( attribute.getQuoteChar() );
+    if(attribute.hasValue()) {
+      String inputValue = attribute.getValue();
+      String outputValue = inputValue;
+      try {
+        Level tag = stack.peek();
+        outputValue = filterAttribute( tag.getQName(), tag.getQName( attribute.getName()
), inputValue, null );
+        if( outputValue == null ) {
+          outputValue = inputValue;
+        }
+      } catch ( Exception e ) {
+        LOG.failedToFilterAttribute( attribute.getName(), e );
+      }
+      writer.write( "=" );
+      writer.write( attribute.getQuoteChar() );
+      writer.write( outputValue );
+      writer.write( attribute.getQuoteChar() );
+    }
   }
 
   private void processText( Segment segment ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/e7d7516b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
index 2150cca..c790e89 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBaseTest.java
@@ -66,6 +66,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
 import static org.xmlmatchers.XmlMatchers.hasXPath;
 import static org.xmlmatchers.transform.XmlConverters.the;
 
@@ -206,6 +207,24 @@ public class HtmlFilterReaderBaseTest {
   }
 
   @Test
+  public void testSimpleBooleanAttribute() throws IOException, ParserConfigurationException
{
+    String inputXml = "<root name/>";
+    StringReader inputReader = new StringReader(inputXml);
+    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
+    String outputHtml = new String(IOUtils.toCharArray(filterReader));
+    assertEquals(inputXml, outputHtml);
+  }
+
+  @Test
+  public void testComplexBooleanAttribute() throws IOException, ParserConfigurationException
{
+    String inputXml = "<root boolean non-boolean='value' empty=''/>";
+    StringReader inputReader = new StringReader(inputXml);
+    HtmlFilterReaderBase filterReader = new NoopXmlFilterReader(inputReader);
+    String outputHtml = new String(IOUtils.toCharArray(filterReader));
+    assertEquals(inputXml, outputHtml);
+  }
+
+  @Test
   public void testMappedText() throws IOException, ParserConfigurationException {
     Map<String,String> map = new HashMap<String,String>();
     map.put( "input-text", "output-text" );


Mime
View raw message