Commit 32890597 authored by apavlov@chromium.org's avatar apavlov@chromium.org

DevTools: Fix crash when setting invalid outer XML for an XML document

R=pfeldman, vsevik
BUG=431519

Review URL: https://codereview.chromium.org/729453003

git-svn-id: svn://svn.chromium.org/blink/trunk@185454 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d50be8ee
......@@ -163,3 +163,6 @@ Event NodeRemoved: h3
Running: testInvalidDocumentDoesNotCrash
PASS: No crash
<html xmlns="http://www.w3.org/1999/xhtml">
<html id="html" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
......@@ -44,6 +44,18 @@ function test()
function testChangeNodeName(next)
{
InspectorTest.patchOuterHTML("<h2>Getting involved</h2>", "<h3>Getting involved</h3>", next);
},
function testInvalidDocumentDoesNotCrash(next)
{
var htmlId = InspectorTest.expandedNodeWithId("html").id;
DOMAgent.setOuterHTML(htmlId, "foo", callback);
function callback()
{
InspectorTest.addResult("PASS: No crash");
next();
}
}
]);
}
......
......@@ -85,6 +85,8 @@ void DOMPatchSupport::patchDocument(const String& markup)
RefPtrWillBeRawPtr<Document> newDocument = nullptr;
if (document().isHTMLDocument())
newDocument = HTMLDocument::create();
else if (document().isSVGDocument())
newDocument = XMLDocument::createSVG();
else if (document().isXHTMLDocument())
newDocument = XMLDocument::createXHTML();
else if (document().isXMLDocument())
......@@ -92,16 +94,18 @@ void DOMPatchSupport::patchDocument(const String& markup)
ASSERT(newDocument);
newDocument->setContextFeatures(document().contextFeatures());
RefPtrWillBeRawPtr<DocumentParser> parser = nullptr;
if (document().isHTMLDocument())
parser = HTMLDocumentParser::create(toHTMLDocument(*newDocument), false);
else
parser = XMLDocumentParser::create(*newDocument, 0);
if (!document().isHTMLDocument()) {
RefPtrWillBeRawPtr<DocumentParser> parser = XMLDocumentParser::create(*newDocument, nullptr);
parser->pinToMainThread();
parser->insert(markup); // Use insert() so that the parser will not yield.
parser->append(markup.impl());
parser->finish();
parser->detach();
// Avoid breakage on non-well-formed documents.
if (!static_cast<XMLDocumentParser*>(parser.get())->wellFormed())
return;
}
newDocument->setContent(markup);
OwnPtr<Digest> oldInfo = createDigest(document().documentElement(), 0);
OwnPtr<Digest> newInfo = createDigest(newDocument->documentElement(), &m_unusedNodesMap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment