diff --git a/content/base/src/nsDOMAttribute.cpp b/content/base/src/nsDOMAttribute.cpp index 17ba1c55ae06..d84743cf1d86 100644 --- a/content/base/src/nsDOMAttribute.cpp +++ b/content/base/src/nsDOMAttribute.cpp @@ -178,12 +178,33 @@ nsDOMAttribute::GetName(nsAString& aName) return NS_OK; } +already_AddRefed +nsDOMAttribute::GetNameAtom(nsIContent* aContent) +{ + nsIAtom* result = nsnull; + if (mNodeInfo->NamespaceID() == kNameSpaceID_None && + aContent->IsInHTMLDocument() && + aContent->IsHTML()) { + nsAutoString name; + mNodeInfo->NameAtom()->ToString(name); + nsAutoString lower; + ToLowerCase(name, lower); + nsCOMPtr nameAtom = do_GetAtom(lower); + nameAtom.swap(result); + } else { + nsCOMPtr nameAtom = mNodeInfo->NameAtom(); + nameAtom.swap(result); + } + return result; +} + NS_IMETHODIMP nsDOMAttribute::GetValue(nsAString& aValue) { nsIContent* content = GetContentInternal(); if (content) { - content->GetAttr(mNodeInfo->NamespaceID(), mNodeInfo->NameAtom(), aValue); + nsCOMPtr nameAtom = GetNameAtom(content); + content->GetAttr(mNodeInfo->NamespaceID(), nameAtom, aValue); } else { aValue = mValue; @@ -198,8 +219,9 @@ nsDOMAttribute::SetValue(const nsAString& aValue) nsresult rv = NS_OK; nsIContent* content = GetContentInternal(); if (content) { + nsCOMPtr nameAtom = GetNameAtom(content); rv = content->SetAttr(mNodeInfo->NamespaceID(), - mNodeInfo->NameAtom(), + nameAtom, mNodeInfo->GetPrefixAtom(), aValue, PR_TRUE); @@ -441,14 +463,14 @@ nsDOMAttribute::SetPrefix(const nsAString& aPrefix) nsIContent* content = GetContentInternal(); if (content) { - nsIAtom *name = mNodeInfo->NameAtom(); + nsCOMPtr name = GetNameAtom(content); PRInt32 nameSpaceID = mNodeInfo->NamespaceID(); nsAutoString tmpValue; if (content->GetAttr(nameSpaceID, name, tmpValue)) { content->UnsetAttr(nameSpaceID, name, PR_TRUE); - content->SetAttr(newNodeInfo->NamespaceID(), newNodeInfo->NameAtom(), + content->SetAttr(newNodeInfo->NamespaceID(), name, newNodeInfo->GetPrefixAtom(), tmpValue, PR_TRUE); } } diff --git a/content/base/src/nsDOMAttribute.h b/content/base/src/nsDOMAttribute.h index 3e254cae8aa0..b5f8c9ee30a6 100644 --- a/content/base/src/nsDOMAttribute.h +++ b/content/base/src/nsDOMAttribute.h @@ -126,6 +126,8 @@ protected: static PRBool sInitialized; private: + already_AddRefed GetNameAtom(nsIContent* aContent); + nsresult EnsureChildState(PRBool aSetText, PRBool &aHasChild) const; PRUint32 GetChildCount(PRBool aSetText) const diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index f38e3b50a5fa..2df085e5e304 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -51,6 +51,7 @@ #include "nsContentUtils.h" #include "nsNodeInfoManager.h" #include "nsAttrName.h" +#include "nsUnicharUtils.h" //---------------------------------------------------------------------- @@ -336,6 +337,13 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode, NS_ENSURE_SUCCESS(rv, rv); } else { + if (mContent->IsInHTMLDocument() && + mContent->IsHTML()) { + nsAutoString lower; + ToLowerCase(name, lower); + name = lower; + } + rv = mContent->NodeInfo()->NodeInfoManager()-> GetNodeInfo(name, nsnull, kNameSpaceID_None, getter_AddRefs(ni)); NS_ENSURE_SUCCESS(rv, rv); @@ -353,19 +361,8 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode, NS_ENSURE_SUCCESS(rv, rv); iAttribute->SetMap(this); - if (!aWithNS && ni->NamespaceID() == kNameSpaceID_None && - mContent->IsHTML()) { - // Set via setAttribute(), which may do normalization on the - // attribute name for HTML - nsCOMPtr ourElement(do_QueryInterface(mContent)); - NS_ASSERTION(ourElement, "HTML content that's not an element?"); - rv = ourElement->SetAttribute(name, value); - } - else { - // It's OK to just use SetAttr - rv = mContent->SetAttr(ni->NamespaceID(), ni->NameAtom(), - ni->GetPrefixAtom(), value, PR_TRUE); - } + rv = mContent->SetAttr(ni->NamespaceID(), ni->NameAtom(), + ni->GetPrefixAtom(), value, PR_TRUE); if (NS_FAILED(rv)) { DropAttribute(ni->NamespaceID(), ni->NameAtom()); } diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index 4ea4ebe781cb..b6c8195cd09c 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -266,6 +266,7 @@ _TEST_FILES = test_bug5141.html \ test_bug513194.html \ test_bug461735.html \ test_bug380418.html \ + test_bug469304.html \ test_bug465767.html \ test_bug380418.html^headers^ \ test_bug422403-1.html \ diff --git a/content/base/test/test_bug469304.html b/content/base/test/test_bug469304.html new file mode 100644 index 000000000000..1a6091514502 --- /dev/null +++ b/content/base/test/test_bug469304.html @@ -0,0 +1,169 @@ + + + + + Test for Bug 469304 + + + + + +Mozilla Bug 469304 +

+ +
+
+
+ +