You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2009/04/08 20:02:01 UTC
svn commit: r763334 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java
main/java/org/apache/tapestry5/dom/Element.java
test/java/org/apache/tapestry5/dom/DOMTest.java
Author: hlship
Date: Wed Apr 8 18:02:00 2009
New Revision: 763334
URL: http://svn.apache.org/viewvc?rev=763334&view=rev
Log:
TAP5-636: Using Element.forceAttribute() with a null value can cause a later NPE during rendering under some circumstances
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java?rev=763334&r1=763333&r2=763334&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java Wed Apr 8 18:02:00 2009
@@ -14,6 +14,8 @@
package org.apache.tapestry5.dom;
+import org.apache.tapestry5.ioc.internal.util.Defense;
+
public abstract class AbstractMarkupModel implements MarkupModel
{
private final boolean useApostropheForAttributes;
@@ -91,6 +93,8 @@
public void encodeQuoted(String content, StringBuilder builder)
{
+ Defense.notNull(content, "content");
+
int length = content.length();
for (int i = 0; i < length; i++)
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java?rev=763334&r1=763333&r2=763334&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java Wed Apr 8 18:02:00 2009
@@ -157,6 +157,10 @@
cursor = cursor.nextAttribute;
}
+ // Don't add a Attribute if the value is null.
+
+ if (value == null) return;
+
firstAttribute = new Attribute(this, namespace, name, value, firstAttribute);
}
@@ -181,7 +185,8 @@
}
/**
- * Forces changes to a number of attributes. The new attributes <em>overwrite</em> previous values.
+ * Forces changes to a number of attributes. The new attributes <em>overwrite</em> previous values. Overriding an
+ * attribute's value to null will remove the attribute entirely.
*/
public Element forceAttributes(String... namesAndValues)
{
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java?rev=763334&r1=763333&r2=763334&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java Wed Apr 8 18:02:00 2009
@@ -18,8 +18,8 @@
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.testng.annotations.Test;
-import java.util.List;
import java.util.Collection;
+import java.util.List;
/**
* Tests for a number of DOM node classes, including {@link org.apache.tapestry5.dom.Element} and {@link
@@ -849,4 +849,19 @@
assertEquals(attribute.getName(), "fred");
assertEquals(attribute.getValue(), "flintstone");
}
+
+ /**
+ * TAP5-636
+ */
+ @Test
+ public void force_null_for_first_attribute_is_noop()
+ {
+ Document d = new Document();
+
+ Element root = d.newRootElement("root");
+
+ root.forceAttributes("null", null);
+
+ assertEquals(root.toString(), "<root></root>");
+ }
}