Bug 937003 - Use correct adjusted insertion location for foster parenting in template element. r=hsivonen

This commit is contained in:
William Chen 2013-11-10 22:45:43 -08:00
parent a590bca00b
commit 7c1cdb0c26
5 changed files with 61 additions and 16 deletions

View File

@ -5644,16 +5644,19 @@ public abstract class TreeBuilder<T> implements TokenHandler,
charBufferLen = 0;
return;
}
int eltPos = findLastOrRoot(TreeBuilder.TABLE);
StackNode<T> node = stack[eltPos];
T elt = node.node;
if (eltPos == 0) {
appendCharacters(elt, charBuffer, 0, charBufferLen);
int tablePos = findLastOrRoot(TreeBuilder.TABLE);
int templatePos = findLastOrRoot(TreeBuilder.TEMPLATE);
if (templatePos >= tablePos) {
appendCharacters(stack[templatePos].node, charBuffer, 0, charBufferLen);
charBufferLen = 0;
return;
}
StackNode<T> tableElt = stack[tablePos];
insertFosterParentedCharacters(charBuffer, 0, charBufferLen,
elt, stack[eltPos - 1].node);
tableElt.node, stack[tablePos - 1].node);
charBufferLen = 0;
return;
}

View File

@ -4124,15 +4124,15 @@ nsHtml5TreeBuilder::flushCharacters()
charBufferLen = 0;
return;
}
int32_t eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
nsHtml5StackNode* node = stack[eltPos];
nsIContent** elt = node->node;
if (!eltPos) {
appendCharacters(elt, charBuffer, 0, charBufferLen);
int32_t tablePos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
int32_t templatePos = findLastOrRoot(NS_HTML5TREE_BUILDER_TEMPLATE);
if (templatePos >= tablePos) {
appendCharacters(stack[templatePos]->node, charBuffer, 0, charBufferLen);
charBufferLen = 0;
return;
}
insertFosterParentedCharacters(charBuffer, 0, charBufferLen, elt, stack[eltPos - 1]->node);
nsHtml5StackNode* tableElt = stack[tablePos];
insertFosterParentedCharacters(charBuffer, 0, charBufferLen, tableElt->node, stack[tablePos - 1]->node);
charBufferLen = 0;
return;
}

View File

@ -226,6 +226,24 @@ nsHtml5TreeOperation::AppendToDocument(nsIContent* aNode,
return rv;
}
static bool
IsElementOrTemplateContent(nsINode* aNode) {
if (aNode) {
if (aNode->IsElement()) {
return true;
} else if (aNode->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
// Check if the node is a template content.
mozilla::dom::DocumentFragment* frag =
static_cast<mozilla::dom::DocumentFragment*>(aNode);
nsIContent* fragHost = frag->GetHost();
if (fragHost && nsNodeUtils::IsTemplateElement(fragHost)) {
return true;
}
}
}
return false;
}
nsresult
nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
nsIContent** aScriptElement)
@ -279,7 +297,7 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
nsIContent* table = *(mThree.node);
nsIContent* foster = table->GetParent();
if (foster && foster->IsElement()) {
if (IsElementOrTemplateContent(foster)) {
aBuilder->FlushPendingAppendNotifications();
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),
@ -487,10 +505,9 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
PRUnichar* buffer = mTwo.unicharPtr;
uint32_t length = mFour.integer;
nsIContent* table = *mThree.node;
nsIContent* foster = table->GetParent();
if (foster && foster->IsElement()) {
if (IsElementOrTemplateContent(foster)) {
aBuilder->FlushPendingAppendNotifications();
nsHtml5OtherDocUpdate update(foster->OwnerDoc(),

View File

@ -8,5 +8,4 @@ var html5Exceptions = {
"<!doctype html><keygen><frameset>" : true, // Bug 101019
"<select><keygen>" : true, // Bug 101019
"<!DOCTYPE html><body><keygen>A" : true, // Bug 101019
"<template><template><table>Foo" : true, // Bug 937003
}

View File

@ -540,6 +540,18 @@
| <tr>
| <div>
#data
<body><template><tr>Foo</tr></template>
#errors
#document
| <html>
| <head>
| <body>
| <template>
| content
| <tr>
| "Foo"
#data
<body><template><tr></tr><td></td></template>
#errors
@ -1144,6 +1156,20 @@
| <table>
| <body>
#data
<template><template><table><div>
#errors
#document
| <html>
| <head>
| <template>
| content
| <template>
| content
| <div>
| <table>
| <body>
#data
<template><template><frame>
#errors