Bug 412257 - Allow createComment("--"); r=bz
authorAryeh Gregor <ayg@aryeh.name>
Fri, 15 Jun 2012 15:13:14 +0300
changeset 96829 bc241a81c6a5ddbc20f7402e9a9b06ae0c3e9e74
parent 96828 d0f514bd6ebcfc46bcb0232464af47211f286be4
child 96830 a61e819c1855629f0cae542b3dd62a95cedb1280
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbz
bugs412257
milestone16.0a1
Bug 412257 - Allow createComment("--"); r=bz
content/base/src/nsDocument.cpp
content/base/test/test_bug352728.html
content/base/test/test_bug352728.xhtml
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -4414,22 +4414,16 @@ nsDocument::CreateDocumentFragment(nsIDO
   return NS_NewDocumentFragment(aReturn, mNodeInfoManager);
 }
 
 NS_IMETHODIMP
 nsDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn)
 {
   *aReturn = nsnull;
 
-  // Make sure the substring "--" is not present in aData.  Otherwise
-  // we'll create a document that can't be serialized.
-  if (FindInReadable(NS_LITERAL_STRING("--"), aData)) {
-    return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
-  }
-
   nsCOMPtr<nsIContent> comment;
   nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), mNodeInfoManager);
 
   if (NS_SUCCEEDED(rv)) {
     // Don't notify; this node is still being created.
     comment->SetText(aData, false);
 
     rv = CallQueryInterface(comment, aReturn);
--- a/content/base/test/test_bug352728.html
+++ b/content/base/test/test_bug352728.html
@@ -39,42 +39,32 @@ function testCharacterData(aNode, aText)
 {
   is(aNode.length, aText.length, "Text length should match");
   is(aNode.data, aText, "Text content should match");
   is(aNode.nodeValue, aText, "Check nodeValue");
   is(aNode.localName, null, "Check localName")
   is(aNode.namespaceURI, null, "Check namespaceURI");
 }
 
-function testComment(aText, aShouldSucceed)
+function testComment(aText)
 {
   try {
     var comment = document.createComment(aText);
     var types = [ Comment, CharacterData, Node ];
     checkTypes(comment, "comment", types);
 
     var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode",
                        "nsIDOMEventTarget" ];
     checkInterfaces(comment, "comment", interfaces);
 
     testCharacterData(comment, aText);
     is(comment.nodeName, "#comment", "Check nodeName");
     is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
-
-    if (!aShouldSucceed) {
-      ok(0, "Invalid comment creation",
-         "Shouldn't create comment with embedded \"--\"");
-    }
   } catch (e) {
-    if (aShouldSucceed) {
-      ok(0, "Correct functioning of comment stuff", "something broke: " + e);
-    } else {
-      is(e.name, "InvalidCharacterError", "Check exception");
-      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
-    }
+    ok(0, "Correct functioning of comment stuff", "something broke: " + e);
   }
 }
 
 function testCDATASection(aText, aShouldSucceed)
 {
   try {
     var cdataSection = document.createCDATASection(aText);
     ok(0, "Invalid CDATA section creation",
@@ -114,21 +104,21 @@ function testPI(aTarget, aData, aShouldS
          "something broke: " + e);
     } else {
       is(e.name, "InvalidCharacterError", "Check exception");
       is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
     }
   }
 }
 
-testComment("Some text", true);
-testComment("Some text with a '-' in it", true);
-testComment("Some text with a '-' and a '-' and another '-'", true);
-testComment("Some text -- this shouldn't create a node!", false);
-testComment("<!-- This is an HTML comment -->", false);
+testComment("Some text");
+testComment("Some text with a '-' in it");
+testComment("Some text with a '-' and a '-' and another '-'");
+testComment("Some text -- this shouldn't create a node!");
+testComment("<!-- This is an HTML comment -->");
 
 testCDATASection("Some text", true);
 testCDATASection("Some text with a '?' in it", true);
 testCDATASection("Some text with a '>' in it", true);
 testCDATASection("Some text with a '?' and a '>' in it", true);
 testCDATASection("Some text with a '? >' in it", true);
 testCDATASection("Some text -- ?> this should be ok", true);
 testCDATASection("Some text ]]&gt; this should not create a node!", false);
--- a/content/base/test/test_bug352728.xhtml
+++ b/content/base/test/test_bug352728.xhtml
@@ -63,42 +63,32 @@ function testCharacterData(aNode, aText)
 {
   is(aNode.length, aText.length, "Text length should match");
   is(aNode.data, aText, "Text content should match");
   is(aNode.nodeValue, aText, "Check nodeValue");
   is(aNode.localName, null, "Check localName")
   is(aNode.namespaceURI, null, "Check namespaceURI");
 }
 
-function testComment(aText, aShouldSucceed)
+function testComment(aText)
 {
   try {
     var comment = document.createComment(aText);
     var types = [ Comment, CharacterData, Node ];
     checkTypes(comment, "comment", types);
 
     var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode",
                        "nsIDOMEventTarget" ];
     checkInterfaces(comment, "comment", interfaces);
 
     testCharacterData(comment, aText);
     is(comment.nodeName, "#comment", "Check nodeName");
     is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
-
-    if (!aShouldSucceed) {
-      ok(0, "Invalid comment creation",
-         "Shouldn't create comment with embedded \"--\"");
-    }
   } catch (e) {
-    if (aShouldSucceed) {
-      ok(0, "Correct functioning of comment stuff", "something broke: " + e);
-    } else {
-      is(e.name, "InvalidCharacterError", "Check exception");
-      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
-    }
+    ok(0, "Correct functioning of comment stuff", "something broke: " + e);
   }
 }
 
 function testCDATASection(aText, aShouldSucceed)
 {
   try {
     var cdataSection = document.createCDATASection(aText);
     var types = [ CDATASection, CharacterData, Node ];
@@ -158,21 +148,21 @@ function testPI(aTarget, aData, aShouldS
          "something broke: " + e);
     } else {
       is(e.name, "InvalidCharacterError", "Check exception");
       is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
     }
   }
 }
 
-testComment("Some text", true);
-testComment("Some text with a '-' in it", true);
-testComment("Some text with a '-' and a '-' and another '-'", true);
-testComment("Some text -- this shouldn't create a node!", false);
-testComment("<!-- This is an HTML comment -->", false);
+testComment("Some text");
+testComment("Some text with a '-' in it");
+testComment("Some text with a '-' and a '-' and another '-'");
+testComment("Some text -- this should create a node!");
+testComment("<!-- This is an HTML comment -->");
 
 testCDATASection("Some text", true);
 testCDATASection("Some text with a '?' in it", true);
 testCDATASection("Some text with a '>' in it", true);
 testCDATASection("Some text with a '?' and a '>' in it", true);
 testCDATASection("Some text with a '? >' in it", true);
 testCDATASection("Some text -- ?> this should be ok", true);
 ]]>