Bug 585819 - When the context passed to Range.createContextualFragment is "html" in an HTML document, use "body" as the context instead. r=bzbarsky, a=blocking2.0-betaN.

This commit is contained in:
Henri Sivonen 2010-09-01 14:41:07 +03:00
parent d2bf08d058
commit 487c2220d2
4 changed files with 47 additions and 1 deletions

View File

@ -1046,6 +1046,11 @@ public:
* Creates a DocumentFragment from text using a context node to resolve
* namespaces.
*
* Note! In the HTML case with the HTML5 parser enabled, this is only called
* from Range.createContextualFragment() and the implementation here is
* quirky accordingly (html context node behaves like a body context node).
* If you don't want that quirky behavior, don't use this method as-is!
*
* @param aContextNode the node which is used to resolve namespaces
* @param aFragment the string which is parsed to a DocumentFragment
* @param aWillOwnFragment is PR_TRUE if ownership of the fragment should be

View File

@ -3896,7 +3896,9 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode,
}
nsCOMPtr<nsIContent> fragment = do_QueryInterface(frag);
if (contextAsContent) {
if (contextAsContent &&
!(nsGkAtoms::html == contextAsContent->Tag() &&
contextAsContent->IsHTML())) {
parser->ParseFragment(aFragment,
fragment,
contextAsContent->Tag(),

View File

@ -120,6 +120,7 @@ _TEST_FILES = \
test_DOMWindowCreated_chromeonly.html \
test_bug581072.html \
test_bug583225.html \
test_bug585819.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,38 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=585819
-->
<head>
<title>Test for Bug 585819</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=585819">Mozilla Bug 585819</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 585819 **/
var range = document.createRange();
range.setStartBefore(document.body);
var fragment = range.createContextualFragment("<span></span>");
is(fragment.firstChild.localName, "span", "We don't want tag inference here!");
var iframeDoc = document.getElementsByTagName("iframe")[0].contentDocument;
var root = iframeDoc.documentElement;
is(root.localName, "html", "Wrong root.");
root.innerHTML = "<span></span>";
is(root.firstChild.localName, "head", "We want inference here!");
</script>
</pre>
</body>
</html>