Bug 750096. r=bzbarsky.

This commit is contained in:
Henri Sivonen 2012-06-14 09:14:47 +03:00
parent d839c86659
commit 79e3d21a31
4 changed files with 26 additions and 0 deletions

View File

@ -177,6 +177,11 @@ class NS_STACK_CLASS nsTreeSanitizer {
nsIDocument* aDocument,
nsIURI* aBaseURI);
/**
* Removes all attributes from an element node.
*/
void RemoveAllAttributes(nsIContent* aElement);
/**
* The whitelist of HTML elements.
*/

View File

@ -1409,6 +1409,11 @@ nsTreeSanitizer::SanitizeChildren(nsINode* aRoot)
PRInt32 ns = nodeInfo->NamespaceID();
if (MustPrune(ns, localName, elt)) {
RemoveAllAttributes(node);
nsIContent* descendant = node;
while ((descendant = descendant->GetNextNode(node))) {
RemoveAllAttributes(descendant);
}
nsIContent* next = node->GetNextNonChildNode(aRoot);
node->GetParent()->RemoveChild(node);
node = next;
@ -1452,6 +1457,7 @@ nsTreeSanitizer::SanitizeChildren(nsINode* aRoot)
continue;
}
if (MustFlatten(ns, localName)) {
RemoveAllAttributes(node);
nsIContent* next = node->GetNextNode(aRoot);
nsIContent* parent = node->GetParent();
nsCOMPtr<nsIContent> child; // Must keep the child alive during move
@ -1504,6 +1510,17 @@ nsTreeSanitizer::SanitizeChildren(nsINode* aRoot)
}
}
void
nsTreeSanitizer::RemoveAllAttributes(nsIContent* aElement)
{
const nsAttrName* attrName;
while ((attrName = aElement->GetAttrNameAt(0))) {
PRInt32 attrNs = attrName->NamespaceID();
nsCOMPtr<nsIAtom> attrLocal = attrName->LocalName();
aElement->UnsetAttr(attrNs, attrLocal, false);
}
}
void
nsTreeSanitizer::InitializeStatics()
{

View File

@ -2297,6 +2297,8 @@ nsresult nsHTMLEditor::ParseFragment(const nsAString & aFragStr,
nsCOMPtr<nsIDOMNode> *outNode,
bool aTrustedInput)
{
nsAutoScriptBlockerSuppressNodeRemoved autoBlocker;
nsCOMPtr<nsIDOMDocumentFragment> frag;
NS_NewDocumentFragment(getter_AddRefs(frag),
aTargetDocument->NodeInfoManager());

View File

@ -149,6 +149,8 @@ nsParserUtils::ParseFragment(const nsAString& aFragment,
document = do_QueryInterface(domDocument);
NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
nsAutoScriptBlockerSuppressNodeRemoved autoBlocker;
// stop scripts
nsRefPtr<nsScriptLoader> loader;
bool scripts_enabled = false;