Updated Branches:
  refs/heads/5.4-js-rewrite 7b397e31d -> d25c14234

TAP5-1976: XML Parser adds attributes with default values and produces invalid 
HTML5 markup


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

Branch: refs/heads/5.4-js-rewrite
Commit: d25c142345e03869f71ab7f4133734cc8eb2ee13
Parents: 7b397e3
Author: Howard M. Lewis Ship <[email protected]>
Authored: Fri Aug 17 16:11:22 2012 -0700
Committer: Howard M. Lewis Ship <[email protected]>
Committed: Fri Aug 17 16:11:22 2012 -0700

----------------------------------------------------------------------
 .../internal/services/XMLTokenStream.java          |   13 +++++-
 .../internal/services/TemplateParserImplTest.java  |   37 +++++++++++++--
 .../services/default_attributes_not_included.tml   |    1 +
 3 files changed, 46 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d25c1423/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/XMLTokenStream.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/XMLTokenStream.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/XMLTokenStream.java
index dc830ce..a2b04d8 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/XMLTokenStream.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/XMLTokenStream.java
@@ -1,4 +1,4 @@
-// Copyright 2009, 2011 The Apache Software Foundation
+// Copyright 2009, 2011, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import 
org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.LocationImpl;
 import org.xml.sax.*;
+import org.xml.sax.ext.Attributes2;
 import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.XMLReaderFactory;
 
@@ -198,6 +199,8 @@ public class XMLTokenStream
             // The XML parser tends to reuse the same Attributes object, so
             // capture the data out of it.
 
+            Attributes2 a2 = (attributes instanceof Attributes2) ? 
(Attributes2) attributes : null;
+
             if (attributes.getLength() == 0)
             {
                 token.attributes = Collections.emptyList();
@@ -207,6 +210,14 @@ public class XMLTokenStream
 
                 for (int i = 0; i < attributes.getLength(); i++)
                 {
+                    // Filter out attributes that are not present in the XML 
input stream, but were
+                    // instead provided by DTD defaulting.
+
+                    if (a2 != null && !a2.isSpecified(i))
+                    {
+                        continue;
+                    }
+
                     String prefixedName = attributes.getQName(i);
 
                     int lastColon = prefixedName.lastIndexOf(':');

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d25c1423/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
index 496a43e..7335805 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software 
Foundation
+// Copyright 2006-2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -1017,10 +1017,39 @@ public class TemplateParserImplTest extends 
InternalBaseTestCase
     {
         List<TemplateToken> tokens = 
tokens("block_can_nest_inside_extend.tml");
 
-        System.out.println(tokens);
-        
         BlockToken token = get(tokens, 0);
 
-        assert (token.getId().equals("myBlock"));
+        assertEquals(token.getId(), "myBlock");
+    }
+
+    /**
+     * See <a 
href="https://issues.apache.org/jira/browse/TAP5-1976";>TAP5-1976</a>
+     *
+     * @since 5.3.5
+     */
+    @Test
+    public void default_attributes_not_included()
+    {
+        List<TemplateToken> tokens = 
tokens("default_attributes_not_included.tml");
+
+        assertEquals(tokens.size(), 2);
+
+        // TAP5-1976 meant that a default attribute ("Attribute[shape=rect]") 
would be included.
+
+        assertEquals(toString(tokens), "Start[a] End");
+    }
+
+    private String toString(List<TemplateToken> tokens)
+    {
+        StringBuilder builder = new StringBuilder();
+        String sep = "";
+
+        for (TemplateToken token : tokens)
+        {
+            builder.append(sep).append(token.toString());
+            sep = " ";
+        }
+
+        return builder.toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d25c1423/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/default_attributes_not_included.tml
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/default_attributes_not_included.tml
 
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/default_attributes_not_included.tml
new file mode 100644
index 0000000..bb9b580
--- /dev/null
+++ 
b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/default_attributes_not_included.tml
@@ -0,0 +1 @@
+<a/>
\ No newline at end of file

Reply via email to