haikuwebkit/LayoutTests/svg/foreignObject/foreign-object-dynamic-pars...

73 lines
3.0 KiB
XML
Raw Permalink Normal View History

Default NamepaceURI must be gotten from the topmost parent before the SVG <foreignObject> https://bugs.webkit.org/show_bug.cgi?id=203868 Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-11-07 Reviewed by Ryosuke Niwa. Source/WebCore: Ensure that we don't cross boundaries from HTML to SVG when traversing the tree of nodes upward. We need to stop at the foreignObject if it is one of the ancestors of the contextElement. Tests: svg/foreignObject/foreign-object-dynamic-parsing.svg * html/HTMLTableCellElement.cpp: (WebCore::HTMLTableCellElement::HTMLTableCellElement): This assertion should not fire if the tag has a prefix like <h:th> or <h:td> where 'h' is a defined namespace. * xml/parser/XMLDocumentParser.cpp: (WebCore::XMLDocumentParser::parseDocumentFragment): Stop at the first SVG <foreignObject> ancestor when calculating the defaultNamespaceURI. * xml/parser/XMLDocumentParser.h: * xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::XMLDocumentParser::XMLDocumentParser): (WebCore::XMLDocumentParser::startElementNs): We need to special case setting the namespaceURI of the SVGElmenets. The defaultNamespaceURI can be wrong for them if the context element is an HTML element, <div> for example, and the innerHTML is set to something like: '<svg><rect/></svg>'. LayoutTests: * svg/foreignObject/foreign-object-dynamic-parsing-expected.svg: Added. * svg/foreignObject/foreign-object-dynamic-parsing.svg: Added. Canonical link: https://commits.webkit.org/217325@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252230 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-08 02:52:40 +00:00
<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:s="http://www.w3.org/2000/svg">
<script><![CDATA[
function createSVGElement(name, attrs, parentElement) {
const svgNamespace = "http://www.w3.org/2000/svg";
var element = document.createElementNS(svgNamespace, name);
for (var key in attrs)
element.setAttribute(key, attrs[key]);
parentElement.appendChild(element);
return element;
}
function createHTMLElement(name) {
const xhtmlNamespace = "http://www.w3.org/1999/xhtml";
return document.createElementNS(xhtmlNamespace, name);
}
var root = document.documentElement;
var foreignObject1 = createSVGElement("foreignObject", { x: 10, y: 10, width: 100, height: 100 }, root);
foreignObject1.appendChild(createHTMLElement("div"));
foreignObject1.lastChild.innerHTML =
"<h2>ABC</h2>" +
"<table style='border: 1px solid black;'>" +
"<thead>" +
"<tr>" +
"<th>A</th>" +
"<th>B</th>" +
"<th>C</th>" +
"</tr>" +
"</thead>" +
"</table>";
var foreignObject2 = createSVGElement("foreignObject", { x: 120, y: 10, width: 100, height: 100 }, root);
foreignObject2.appendChild(createHTMLElement("h:div"));
foreignObject2.lastChild.innerHTML =
"<h:h2>DEF</h:h2>" +
"<h:table style='border: 1px solid black;'>" +
"<h:thead>" +
"<h:tr>" +
"<h:th>D</h:th>" +
"<h:th>E</h:th>" +
"<h:th>F</h:th>" +
"</h:tr>" +
"</h:thead>" +
"</h:table>";
var foreignObject3 = createSVGElement("foreignObject", { x: 10, y: 120, width: 100, height: 100 }, root);
foreignObject3.appendChild(createHTMLElement("h:div"));
foreignObject3.lastChild.innerHTML =
"<svg>" +
"<rect width='100' height='100' fill='green'/>" +
"</svg>";
var foreignObject4 = createSVGElement("foreignObject", { x: 120, y: 120, width: 100, height: 100 }, root);
foreignObject4.appendChild(createHTMLElement("h:div"));
foreignObject4.lastChild.innerHTML =
"<s:svg>" +
"<s:rect width='100' height='100' fill='green'/>" +
"</s:svg>";
var svg1 = createSVGElement("svg", { }, root);
var g1 = createSVGElement("g", { transform: 'translate(10, 230)' }, svg1);
g1.innerHTML = "<rect width='100' height='100' fill='green'/>";
var svg2 = createSVGElement("s:svg", { }, root);
var g2 = createSVGElement("s:g", { transform: 'translate(120, 230)' }, svg2);
g2.innerHTML = "<s:rect width='100' height='100' fill='green'/>";
]]></script>
</svg>