From 71edcafb0ebbce66d240c369c3b681425f7666d7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 11 Mar 2012 09:48:16 +0100 Subject: [PATCH] Bug 649599 - Make getAttributeNS return null for absent attributes; r=peterv --- content/base/src/nsGenericElement.cpp | 11 ++++++----- .../dom-level2-core/test_getAttributeNS03.html | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 88f1167a93d..51e5d9aad86 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -2853,15 +2853,16 @@ nsGenericElement::GetAttributeNS(const nsAString& aNamespaceURI, nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI); if (nsid == kNameSpaceID_Unknown) { - // Unknown namespace means no attr... - - aReturn.Truncate(); - + // Unknown namespace means no attribute. + SetDOMStringToNull(aReturn); return NS_OK; } nsCOMPtr name = do_GetAtom(aLocalName); - GetAttr(nsid, name, aReturn); + bool hasAttr = GetAttr(nsid, name, aReturn); + if (!hasAttr) { + SetDOMStringToNull(aReturn); + } return NS_OK; } diff --git a/dom/tests/mochitest/dom-level2-core/test_getAttributeNS03.html b/dom/tests/mochitest/dom-level2-core/test_getAttributeNS03.html index e9dfcb64e68..5a5a3359464 100644 --- a/dom/tests/mochitest/dom-level2-core/test_getAttributeNS03.html +++ b/dom/tests/mochitest/dom-level2-core/test_getAttributeNS03.html @@ -105,7 +105,7 @@ function getAttributeNS03() { assertNotNull("empAddrNotNull",testAddr); testAddr.removeAttributeNS(namespaceURI,localName); attrValue = testAddr.getAttributeNS(namespaceURI,localName); - assertEquals("throw_Equals","",attrValue); + assertEquals("throw_Equals",null,attrValue); }