зеркало из https://github.com/mozilla/gecko-dev.git
Bug 817469. Correctly handle embedded null in the string to parse in DOMParser. r=emk
This commit is contained in:
Родитель
b8f5cf0684
Коммит
4c3f5120bd
|
@ -61,9 +61,9 @@ nsDOMParser::ParseFromString(const nsAString& aStr, SupportedType aType,
|
|||
ErrorResult& rv)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
rv = nsDOMParser::ParseFromString(PromiseFlatString(aStr).get(),
|
||||
SupportedTypeValues::strings[aType].value,
|
||||
getter_AddRefs(domDocument));
|
||||
rv = ParseFromString(aStr,
|
||||
SupportedTypeValues::strings[aType].value,
|
||||
getter_AddRefs(domDocument));
|
||||
nsCOMPtr<nsIDocument> document(do_QueryInterface(domDocument));
|
||||
return document.forget();
|
||||
}
|
||||
|
@ -74,6 +74,16 @@ nsDOMParser::ParseFromString(const PRUnichar *str,
|
|||
nsIDOMDocument **aResult)
|
||||
{
|
||||
NS_ENSURE_ARG(str);
|
||||
// Converting a string to an enum value manually is a bit of a pain,
|
||||
// so let's just use a helper that takes a content-type string.
|
||||
return ParseFromString(nsDependentString(str), contentType, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMParser::ParseFromString(const nsAString& str,
|
||||
const char *contentType,
|
||||
nsIDOMDocument **aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
nsresult rv;
|
||||
|
@ -96,8 +106,7 @@ nsDOMParser::ParseFromString(const PRUnichar *str,
|
|||
// And the right principal
|
||||
document->SetPrincipal(mPrincipal);
|
||||
|
||||
nsDependentString sourceBuffer(str);
|
||||
rv = nsContentUtils::ParseDocumentHTML(sourceBuffer, document, false);
|
||||
rv = nsContentUtils::ParseDocumentHTML(str, document, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
domDocument.forget(aResult);
|
||||
|
|
|
@ -89,6 +89,10 @@ private:
|
|||
|
||||
nsresult SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult);
|
||||
|
||||
// Helper for ParseFromString
|
||||
nsresult ParseFromString(const nsAString& str, const char *contentType,
|
||||
nsIDOMDocument **aResult);
|
||||
|
||||
class AttemptedInitMarker {
|
||||
public:
|
||||
AttemptedInitMarker(bool* aAttemptedInit) :
|
||||
|
|
|
@ -267,6 +267,7 @@ MOCHITEST_FILES_A = \
|
|||
test_bug782342.html \
|
||||
test_bug282547.html \
|
||||
bug282547.sjs \
|
||||
test_domparser_null_char.html \
|
||||
$(NULL)
|
||||
|
||||
MOCHITEST_FILES_B = \
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=817469
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 817469</title>
|
||||
<script type="application/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=817469">Mozilla Bug 817469</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 817469 **/
|
||||
var doc = new DOMParser().parseFromString("\x00<div id='myElement'>", "text/html");
|
||||
isnot(doc.getElementById("myElement"), null, "Should not stop at null");
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче