Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nested template contents are not cloned by document.importNode
https://bugs.webkit.org/show_bug.cgi?id=137619 Reviewed by Andreas Kling. Source/WebCore: The bug was caused by Document.importNode not cloning HTMLTemplateElement's content. Fixed the bug by sharing code between Document::importNode and Node::cloneNode by generalizing Node::cloneNodeInternal, added in r177314, by taking the owner document as an argument. The most of code changes are the result of adding this argument. Document::importNode is the only function in which the actual logic changes. Note that the code to import TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, PROCESSING_INSTRUCTION_NODE and COMMENT_NODE nodes are identical to that of cloneNode. This patch removes the call to hasValidNamespaceForElements in ELEMENT_NODE but this should not introduce an observable behavior change since all instantiated elements should have a valid namespace in the first place. Because DOCUMENT_NODE and DOCUMENT_TYPE_NODE cannot be imported and DOCUMENT_TYPE_NODE can only appear as a direct child of DOCUMENT_NODE, neither nodes nor unimplemented XPATH_NAMESPACE_NODE and XPATH_NAMESPACE_NODE can appear inside the recursive calls for ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE nodes. While importNode behaves differently from cloneNode for ATTRIBUTE_NODE, namely that it merges all of its child nodes, this behavior isn't present when recursing inside ELEMENT_NODE and DOCUMENT_FRAGMENT_NODE since we are using cloneDataFromElement. Thus there should be no observable behavior changes for DOCUMENT_FRAGMENT_NODE and ELEMENT_NODE nodes either. Test: fast/dom/HTMLTemplateElement/importNode-nested-templates.html * dom/Attr.cpp: (WebCore::Attr::cloneNodeInternal): * dom/Attr.h: * dom/CDATASection.cpp: (WebCore::CDATASection::cloneNodeInternal): * dom/CDATASection.h: * dom/Comment.cpp: (WebCore::Comment::cloneNodeInternal): * dom/Comment.h: * dom/ContainerNode.cpp: (WebCore::ContainerNode::cloneChildNodes): * dom/Document.cpp: (WebCore::Document::importNode): (WebCore::Document::cloneNodeInternal): * dom/Document.h: * dom/DocumentFragment.cpp: (WebCore::DocumentFragment::cloneNodeInternal): * dom/DocumentFragment.h: * dom/DocumentType.cpp: (WebCore::DocumentType::cloneNodeInternal): * dom/DocumentType.h: * dom/Element.cpp: (WebCore::Element::cloneNodeInternal): (WebCore::Element::cloneElementWithChildren): (WebCore::Element::cloneElementWithoutChildren): (WebCore::Element::cloneElementWithoutAttributesAndChildren): * dom/Element.h: * dom/EntityReference.cpp: (WebCore::EntityReference::cloneNodeInternal): * dom/EntityReference.h: * dom/Node.h: (WebCore::Node::cloneNode): * dom/ProcessingInstruction.cpp: (WebCore::ProcessingInstruction::cloneNodeInternal): * dom/ProcessingInstruction.h: * dom/ShadowRoot.cpp: (WebCore::ShadowRoot::cloneNodeInternal): * dom/ShadowRoot.h: * dom/Text.cpp: (WebCore::Text::cloneNodeInternal): * dom/Text.h: * editing/ApplyStyleCommand.cpp: (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode): (WebCore::ApplyStyleCommand::applyInlineStyleChange): * editing/BreakBlockquoteCommand.cpp: (WebCore::BreakBlockquoteCommand::doApply): * editing/InsertParagraphSeparatorCommand.cpp: (WebCore::InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock): (WebCore::InsertParagraphSeparatorCommand::doApply): * editing/ModifySelectionListLevel.cpp: (WebCore::IncreaseSelectionListLevelCommand::doApply): * editing/SplitElementCommand.cpp: (WebCore::SplitElementCommand::doApply): * editing/markup.cpp: (WebCore::createFragmentFromText): * html/HTMLKeygenElement.cpp: * html/HTMLScriptElement.cpp: (WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren): * html/HTMLScriptElement.h: * html/HTMLTemplateElement.cpp: (WebCore::HTMLTemplateElement::cloneNodeInternal): * html/HTMLTemplateElement.h: * html/shadow/SliderThumbElement.cpp: (WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren): * html/shadow/SliderThumbElement.h: * html/track/WebVTTElement.cpp: (WebCore::WebVTTElement::cloneElementWithoutAttributesAndChildren): * html/track/WebVTTElement.h: * svg/SVGScriptElement.cpp: (WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren): * svg/SVGScriptElement.h: * svg/SVGUseElement.cpp: (WebCore::SVGUseElement::buildShadowTree): (WebCore::SVGUseElement::expandUseElementsInShadowTree): LayoutTests: Added a regression test. * fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt: Added. * fast/dom/HTMLTemplateElement/importNode-nested-templates.html: Added. Canonical link: https://commits.webkit.org/157579@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177372 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
46 changed files
with
266 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Test that template contents are cloned when the template element is imported via importNode | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
importedOuterTemplate = anotherDocument.importNode(outerTemplate, true) | ||
PASS outerTemplate.ownerDocument is document | ||
PASS importedOuterTemplate.ownerDocument is anotherDocument | ||
PASS importedOuterTemplate.content is not outerTemplate.content | ||
PASS importedOuterTemplate.content.childNodes.length is 1 | ||
innerTemplate = outerTemplate.content.firstChild | ||
importedInnerTemplate = importedOuterTemplate.content.firstChild | ||
PASS importedInnerTemplate.outerHTML is innerTemplate.outerHTML | ||
PASS innerTemplate.ownerDocument is not importedInnerTemplate.ownerDocument | ||
PASS importedInnerTemplate.content is not innerTemplate.content | ||
PASS innerTemplate.content.childNodes.length is 1 | ||
PASS importedInnerTemplate.content.childNodes.length is 1 | ||
PASS innerTemplate.content.firstChild.outerHTML is importedInnerTemplate.content.firstChild.outerHTML | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
36 changes: 36 additions & 0 deletions
36
LayoutTests/fast/dom/HTMLTemplateElement/importNode-nested-templates.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<template id="outerTemplate"><template id="innerTemplate"><span>Contents</span></template></template> | ||
<iframe></iframe> | ||
<script src="../../../resources/js-test-pre.js"></script> | ||
<script> | ||
|
||
description('Test that template contents are cloned when the template element is imported via importNode'); | ||
|
||
if (!window.HTMLTemplateElement) | ||
testFailed('This test requires ENABLE(TEMPLATE_ELEMENT)'); | ||
|
||
var anotherDocument = document.querySelector('iframe').contentDocument; | ||
|
||
var outerTemplate = document.getElementById('outerTemplate'); | ||
evalAndLog('importedOuterTemplate = anotherDocument.importNode(outerTemplate, true)'); | ||
shouldBe('outerTemplate.ownerDocument', 'document'); | ||
shouldBe('importedOuterTemplate.ownerDocument', 'anotherDocument'); | ||
shouldNotBe('importedOuterTemplate.content', 'outerTemplate.content'); | ||
shouldBe('importedOuterTemplate.content.childNodes.length', '1'); | ||
evalAndLog('innerTemplate = outerTemplate.content.firstChild'); | ||
evalAndLog('importedInnerTemplate = importedOuterTemplate.content.firstChild'); | ||
shouldBe('importedInnerTemplate.outerHTML', 'innerTemplate.outerHTML'); | ||
shouldNotBe('innerTemplate.ownerDocument', 'importedInnerTemplate.ownerDocument'); | ||
shouldNotBe('importedInnerTemplate.content', 'innerTemplate.content'); | ||
shouldBe('innerTemplate.content.childNodes.length', '1'); | ||
shouldBe('importedInnerTemplate.content.childNodes.length', '1'); | ||
shouldBe('innerTemplate.content.firstChild.outerHTML', 'importedInnerTemplate.content.firstChild.outerHTML'); | ||
|
||
var successfullyParsed = true; | ||
|
||
</script> | ||
<script src="../../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.