mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 719533 - Range.extractContents() shouldn't modify the DOM if the range contains a doctype; r=smaug
This commit is contained in:
parent
2c6c03010c
commit
2487a022be
@ -48,6 +48,7 @@
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMDocumentFragment.h"
|
||||
#include "nsIDOMDocumentType.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMText.h"
|
||||
@ -1526,6 +1527,26 @@ nsresult nsRange::CutContents(nsIDOMDocumentFragment** aFragment)
|
||||
nsCOMPtr<nsIDOMNode> endContainer = do_QueryInterface(mEndParent);
|
||||
PRInt32 endOffset = mEndOffset;
|
||||
|
||||
if (retval) {
|
||||
// For extractContents(), abort early if there's a doctype (bug 719533).
|
||||
// This can happen only if the common ancestor is a document, in which case
|
||||
// we just need to find its doctype child and check if that's in the range.
|
||||
nsCOMPtr<nsIDOMDocument> commonAncestorDocument(do_QueryInterface(commonAncestor));
|
||||
if (commonAncestorDocument) {
|
||||
nsCOMPtr<nsIDOMDocumentType> doctype;
|
||||
rv = commonAncestorDocument->GetDoctype(getter_AddRefs(doctype));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (doctype &&
|
||||
nsContentUtils::ComparePoints(startContainer, startOffset,
|
||||
doctype.get(), 0) < 0 &&
|
||||
nsContentUtils::ComparePoints(doctype.get(), 0,
|
||||
endContainer, endOffset) < 0) {
|
||||
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create and initialize a subtree iterator that will give
|
||||
// us all the subtrees within the range.
|
||||
|
||||
|
@ -579,6 +579,7 @@ _TEST_FILES2 = \
|
||||
test_bug650386_redirect_307.html \
|
||||
file_bug650386_content.sjs \
|
||||
file_bug650386_report.sjs \
|
||||
test_bug719533.html \
|
||||
$(NULL)
|
||||
|
||||
_CHROME_FILES = \
|
||||
|
27
content/base/test/test_bug719533.html
Normal file
27
content/base/test/test_bug719533.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!doctype html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=719544
|
||||
-->
|
||||
<title>Test for Bug 719544</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719544">Mozilla Bug 719544</a>
|
||||
<script>
|
||||
|
||||
/** Test for Bug 719544 **/
|
||||
var threw = false;
|
||||
var origLength = document.childNodes.length;
|
||||
try {
|
||||
var range = document.createRange();
|
||||
range.selectNodeContents(document);
|
||||
range.extractContents();
|
||||
} catch(e) {
|
||||
threw = true;
|
||||
is(Object.getPrototypeOf(e), DOMException.prototype,
|
||||
"Must throw DOMException");
|
||||
is(e.name, "HierarchyRequestError", "Must throw HierarchyRequestError");
|
||||
}
|
||||
ok(threw, "Must throw");
|
||||
is(document.childNodes.length, origLength, "Must preserve original children");
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user