Permalink
Browse files

Fixes #71 - null Namespace handling for Element.(get/set/remove)Attri…

…bute*()
  • Loading branch information...
1 parent 23295c9 commit 587efe408670d112f6e1af7094373e20f5a8d0aa @rolfl rolfl committed Apr 7, 2012
Showing with 16 additions and 0 deletions.
  1. +3 −0 core/src/java/org/jdom2/AttributeList.java
  2. +13 −0 test/src/java/org/jdom2/test/cases/TestElement.java
@@ -391,6 +391,9 @@ Attribute get(final String name, final Namespace namespace) {
*/
int indexOf(final String name, final Namespace namespace) {
if (attributeData != null) {
+ if (namespace == null) {
+ return indexOf(name, Namespace.NO_NAMESPACE);
+ }
final String uri = namespace.getURI();
for (int i = 0; i < size; i++) {
final Attribute att = attributeData[i];
@@ -2233,6 +2233,15 @@ public void testSetNamespaceAttribute() {
emt.setNamespace(nsd);
assertTrue(nsd == emt.getNamespace());
+ assertTrue(emt.setAttribute("tst", "val1", null) == emt);
+ assertEquals("val1", emt.getAttributeValue("tst"));
+ assertEquals("val1", emt.getAttributeValue("tst", (Namespace)null));
+ assertEquals("val1", emt.getAttributeValue("tst", Namespace.NO_NAMESPACE));
+ assertTrue(emt.setAttribute("tst", "val2", Namespace.NO_NAMESPACE) == emt);
+ assertEquals("val2", emt.getAttributeValue("tst"));
+ assertEquals("val2", emt.getAttributeValue("tst", (Namespace)null));
+ assertEquals("val2", emt.getAttributeValue("tst", Namespace.NO_NAMESPACE));
+
}
@@ -2468,6 +2477,7 @@ public void testAttributes() {
assertTrue(emt.getAttribute("att") == null);
assertTrue(emt.getAttributeValue("att") == null);
assertTrue(emt.getAttributeValue("att", Namespace.NO_NAMESPACE) == null);
+ assertTrue(emt.getAttributeValue("att", (Namespace)null) == null);
assertTrue(emt.getAttributeValue("att", myns) == null);
assertTrue("def".equals(emt.getAttributeValue("att", "def")));
assertTrue("def".equals(emt.getAttributeValue("att", myns, "def")));
@@ -2478,9 +2488,11 @@ public void testAttributes() {
assertTrue(emt.getAttribute("att") != null);
assertTrue("val".equals(emt.getAttributeValue("att")));
assertTrue("val".equals(emt.getAttributeValue("att", Namespace.NO_NAMESPACE)));
+ assertTrue("val".equals(emt.getAttributeValue("att", (Namespace)null)));
assertTrue(emt.getAttributeValue("att", myns) == null);
assertTrue("val".equals(emt.getAttributeValue("att", "def")));
assertTrue("val".equals(emt.getAttributeValue("att", Namespace.NO_NAMESPACE, "def")));
+ assertTrue("val".equals(emt.getAttributeValue("att", null, "def")));
assertTrue("def".equals(emt.getAttributeValue("att", myns, "def")));
assertTrue(emt.getAdditionalNamespaces().isEmpty());
@@ -2491,6 +2503,7 @@ public void testAttributes() {
assertTrue(emt.getAttribute("att") != emt.getAttribute("att", myns));
assertTrue("val".equals(emt.getAttributeValue("att")));
assertTrue("val".equals(emt.getAttributeValue("att", Namespace.NO_NAMESPACE)));
+ assertTrue("val".equals(emt.getAttributeValue("att", (Namespace)null)));
assertTrue("nsval".equals(emt.getAttributeValue("att", myns)));
assertTrue("nsval".equals(emt.getAttributeValue("att", mynsz)));
assertTrue("val".equals(emt.getAttributeValue("att", "def")));

0 comments on commit 587efe4

Please sign in to comment.