Fix for bug 47852 (NAMESPACE_ERR not being thrown when setting Node.prefix). r/sr=sicking.

This commit is contained in:
peterv%propagandism.org 2006-04-06 20:54:53 +00:00
parent 73ab09a55c
commit 64c5f05794
2 changed files with 55 additions and 0 deletions

View File

@ -54,6 +54,7 @@
#include "nsIDOMUserDataHandler.h"
#include "nsITextContent.h"
#include "nsEventDispatcher.h"
#include "nsGkAtoms.h"
//----------------------------------------------------------------------
PRBool nsDOMAttribute::sInitialized;
@ -431,11 +432,46 @@ nsDOMAttribute::GetPrefix(nsAString& aPrefix)
NS_IMETHODIMP
nsDOMAttribute::SetPrefix(const nsAString& aPrefix)
{
// XXX: Validate the prefix string!
nsCOMPtr<nsINodeInfo> newNodeInfo;
nsCOMPtr<nsIAtom> prefix;
PRBool qnameIsXMLNS = mNodeInfo->NameAtom() == nsGkAtoms::xmlns &&
!mNodeInfo->GetPrefixAtom();
if (!aPrefix.IsEmpty()) {
prefix = do_GetAtom(aPrefix);
if (!prefix) {
return NS_ERROR_OUT_OF_MEMORY;
}
// If the namespace of the attribute is null then setting a non-null prefix
// isn't allowed.
// If the QName of the attribute is |xmlns| then setting a non-null prefix
// isn't allowed.
// If the namespace of the attribute is the XMLNS namespace then setting
// a prefix other than xmlns isn't allowed, if the namespace of the
// attribute is not the XMLNS namespace then setting the prefix to xmlns
// isn't allowed.
if (mNodeInfo->NamespaceID() == kNameSpaceID_None || qnameIsXMLNS ||
((mNodeInfo->NamespaceID() == kNameSpaceID_XMLNS) !=
(prefix == nsGkAtoms::xmlns))) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
}
else if (!qnameIsXMLNS && mNodeInfo->NamespaceID() == kNameSpaceID_XMLNS) {
// Setting the prefix to null on an attribute that is in the XMLNS
// namespace but whose QName isn't |xmlns| is not allowed.
return NS_ERROR_DOM_NAMESPACE_ERR;
}
// If the namespace of the attribute is the XML namespace then setting a
// prefix other than xml isn't allowed, if the namespace of the attribute is
// not the XML namespace then setting the prefix to xml isn't allowed.
if ((mNodeInfo->NamespaceID() == kNameSpaceID_XML) !=
(prefix == nsGkAtoms::xml)) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
nsresult rv = nsContentUtils::PrefixChanged(mNodeInfo, prefix,

View File

@ -1072,6 +1072,25 @@ nsGenericElement::SetPrefix(const nsAString& aPrefix)
if (!aPrefix.IsEmpty()) {
prefix = do_GetAtom(aPrefix);
NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY);
// If the namespace of the element is null then setting a non-null prefix
// isn't allowed.
if (mNodeInfo->NamespaceID() == kNameSpaceID_None) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
}
// If the namespace of the element is the XML namespace then setting a prefix
// other than xml isn't allowed, if the namespace of the element is not the
// XML namespace then setting the prefix to xml isn't allowed.
// If the namespace of the element is the XMLNS namespace then setting a
// prefix other than xmlns isn't allowed, if the namespace of the element is
// not the XMLNS namespace then setting the prefix to xmlns isn't allowed.
if (((mNodeInfo->NamespaceID() == kNameSpaceID_XML) !=
(prefix == nsGkAtoms::xml)) ||
((mNodeInfo->NamespaceID() == kNameSpaceID_XMLNS) !=
(prefix == nsGkAtoms::xmlns))) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
nsCOMPtr<nsINodeInfo> newNodeInfo;