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 ...@@ -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> <head>
<script src="../../http/tests/inspector/inspector-test.js"></script> <script src="../../http/tests/inspector/inspector-test.js"></script>
...@@ -44,6 +44,18 @@ function test() ...@@ -44,6 +44,18 @@ function test()
function testChangeNodeName(next) function testChangeNodeName(next)
{ {
InspectorTest.patchOuterHTML("<h2>Getting involved</h2>", "<h3>Getting involved</h3>", 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) ...@@ -85,6 +85,8 @@ void DOMPatchSupport::patchDocument(const String& markup)
RefPtrWillBeRawPtr<Document> newDocument = nullptr; RefPtrWillBeRawPtr<Document> newDocument = nullptr;
if (document().isHTMLDocument()) if (document().isHTMLDocument())
newDocument = HTMLDocument::create(); newDocument = HTMLDocument::create();
else if (document().isSVGDocument())
newDocument = XMLDocument::createSVG();
else if (document().isXHTMLDocument()) else if (document().isXHTMLDocument())
newDocument = XMLDocument::createXHTML(); newDocument = XMLDocument::createXHTML();
else if (document().isXMLDocument()) else if (document().isXMLDocument())
...@@ -92,16 +94,18 @@ void DOMPatchSupport::patchDocument(const String& markup) ...@@ -92,16 +94,18 @@ void DOMPatchSupport::patchDocument(const String& markup)
ASSERT(newDocument); ASSERT(newDocument);
newDocument->setContextFeatures(document().contextFeatures()); newDocument->setContextFeatures(document().contextFeatures());
RefPtrWillBeRawPtr<DocumentParser> parser = nullptr; if (!document().isHTMLDocument()) {
if (document().isHTMLDocument()) RefPtrWillBeRawPtr<DocumentParser> parser = XMLDocumentParser::create(*newDocument, nullptr);
parser = HTMLDocumentParser::create(toHTMLDocument(*newDocument), false); parser->pinToMainThread();
else parser->append(markup.impl());
parser = XMLDocumentParser::create(*newDocument, 0); parser->finish();
parser->pinToMainThread(); parser->detach();
parser->insert(markup); // Use insert() so that the parser will not yield.
parser->finish(); // Avoid breakage on non-well-formed documents.
parser->detach(); if (!static_cast<XMLDocumentParser*>(parser.get())->wellFormed())
return;
}
newDocument->setContent(markup);
OwnPtr<Digest> oldInfo = createDigest(document().documentElement(), 0); OwnPtr<Digest> oldInfo = createDigest(document().documentElement(), 0);
OwnPtr<Digest> newInfo = createDigest(newDocument->documentElement(), &m_unusedNodesMap); 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