Bug 1515066 - Mark SVG script without an end tag malformed. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D15090

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henri Sivonen 2018-12-20 18:20:04 +00:00
Родитель 115eddc306
Коммит feff447597
4 изменённых файлов: 57 добавлений и 2 удалений

Просмотреть файл

@ -3359,6 +3359,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
}
eltPos = currentPtr;
int origPos = currentPtr;
for (;;) {
if (eltPos == 0) {
assert fragment: "We can get this close to the root of the stack in foreign content only in the fragment case.";
@ -3366,7 +3367,7 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
if (stack[eltPos].name == name) {
while (currentPtr >= eltPos) {
pop();
popForeign(origPos);
}
break endtagloop;
}
@ -5225,6 +5226,17 @@ public abstract class TreeBuilder<T> implements TokenHandler,
node.release(this);
}
private void popForeign(int origPos) throws SAXException {
StackNode<T> node = stack[currentPtr];
if (origPos != currentPtr) {
markMalformedIfScript(node.node);
}
assert debugOnlyClearLastStackSlot();
currentPtr--;
elementPopped(node.ns, node.popName, node.node);
node.release(this);
}
private void silentPop() throws SAXException {
StackNode<T> node = stack[currentPtr];
assert debugOnlyClearLastStackSlot();

Просмотреть файл

@ -2349,6 +2349,7 @@ void nsHtml5TreeBuilder::endTag(nsHtml5ElementName* elementName) {
}
}
eltPos = currentPtr;
int32_t origPos = currentPtr;
for (;;) {
if (!eltPos) {
MOZ_ASSERT(fragment,
@ -2358,7 +2359,7 @@ void nsHtml5TreeBuilder::endTag(nsHtml5ElementName* elementName) {
}
if (stack[eltPos]->name == name) {
while (currentPtr >= eltPos) {
pop();
popForeign(origPos);
}
NS_HTML5_BREAK(endtagloop);
}
@ -4086,6 +4087,17 @@ void nsHtml5TreeBuilder::pop() {
node->release(this);
}
void nsHtml5TreeBuilder::popForeign(int32_t origPos) {
nsHtml5StackNode* node = stack[currentPtr];
if (origPos != currentPtr) {
markMalformedIfScript(node->node);
}
MOZ_ASSERT(debugOnlyClearLastStackSlot());
currentPtr--;
elementPopped(node->ns, node->popName, node->node);
node->release(this);
}
void nsHtml5TreeBuilder::silentPop() {
nsHtml5StackNode* node = stack[currentPtr];
MOZ_ASSERT(debugOnlyClearLastStackSlot());

Просмотреть файл

@ -456,6 +456,7 @@ class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState {
bool isInStack(nsHtml5StackNode* node);
void popTemplateMode();
void pop();
void popForeign(int32_t origPos);
void silentPop();
void popOnEof();
void appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes* attributes);

Просмотреть файл

@ -0,0 +1,30 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
var scriptWithEndTagRan = false;
var scriptWithoutEndTagRan = false;
var scriptWithBogusEndTagInsideRan = false;
</script>
<svg>
<script>scriptWithEndTagRan = true;</script>
</svg>
<svg>
<script>scriptWithoutEndTagRan = true;
</svg>
<svg>
<script>scriptWithBogusEndTagInsideRan = true;</g></script>
</svg>
<script>
test(function() {
assert_true(scriptWithEndTagRan);
}, "SVG scripts with end tag should run");
test(function() {
assert_false(scriptWithoutEndTagRan);
}, "SVG scripts without end tag should not run");
test(function() {
assert_true(scriptWithBogusEndTagInsideRan);
}, "SVG scripts with bogus end tag inside should run");
</script>