Fix for <rdar://problem/5208440> (13753)
REGRESSION: Raw text needs to be pulled outside of tables
Reviewed by aroben
* html/HTMLParser.cpp:
(WebCore::HTMLParser::handleError):
* html/HTMLTableColElement.cpp:
(WebCore::HTMLTableColElement::checkDTD):
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::checkDTD):
* html/HTMLTableRowElement.cpp:
(WebCore::HTMLTableRowElement::checkDTD):
* html/HTMLTableSectionElement.cpp:
(WebCore::HTMLTableSectionElement::checkDTD):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 9d89717..4511abd 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2007-05-24 David Hyatt <hyatt@apple.com>
+
+ Fix for <rdar://problem/5208440> (13753)
+
+ REGRESSION: Raw text needs to be pulled outside of tables
+
+ Reviewed by aroben
+
+ * html/HTMLParser.cpp:
+ (WebCore::HTMLParser::handleError):
+ * html/HTMLTableColElement.cpp:
+ (WebCore::HTMLTableColElement::checkDTD):
+ * html/HTMLTableElement.cpp:
+ (WebCore::HTMLTableElement::checkDTD):
+ * html/HTMLTableRowElement.cpp:
+ (WebCore::HTMLTableRowElement::checkDTD):
+ * html/HTMLTableSectionElement.cpp:
+ (WebCore::HTMLTableSectionElement::checkDTD):
+
2007-05-24 Mitz Pettel <mitz@webkit.org>
Reviewed by Darin.
diff --git a/WebCore/html/HTMLParser.cpp b/WebCore/html/HTMLParser.cpp
index c9a981a..989674b 100644
--- a/WebCore/html/HTMLParser.cpp
+++ b/WebCore/html/HTMLParser.cpp
@@ -492,72 +492,58 @@
popBlock(localName); // end the table
handled = true; // ...and start a new one
} else {
- bool possiblyMoveStrayContent = true;
ExceptionCode ec = 0;
- if (n->isTextNode()) {
- Text* t = static_cast<Text*>(n);
- if (t->containsOnlyWhitespace())
- return false;
- StringImpl* i = t->string();
- unsigned int pos = 0;
- while (pos < i->length() && ((*i)[pos] == ' ' || (*i)[pos] == noBreakSpace))
- pos++;
- if (pos == i->length())
- possiblyMoveStrayContent = false;
- }
- if (possiblyMoveStrayContent) {
- Node* node = current;
+ Node* node = current;
+ Node* parent = node->parentNode();
+ // A script may have removed the current node's parent from the DOM
+ // http://bugs.webkit.org/show_bug.cgi?id=7137
+ // FIXME: we should do real recovery here and re-parent with the correct node.
+ if (!parent)
+ return false;
+ Node* grandparent = parent->parentNode();
+
+ if (n->isTextNode() ||
+ (h->hasLocalName(trTag) &&
+ isTableSection(parent) && grandparent->hasTagName(tableTag)) ||
+ ((!n->hasTagName(tdTag) && !n->hasTagName(thTag) &&
+ !n->hasTagName(formTag) && !n->hasTagName(scriptTag)) && isTableSection(node) &&
+ parent->hasTagName(tableTag))) {
+ node = (node->hasTagName(tableTag)) ? node :
+ ((node->hasTagName(trTag)) ? grandparent : parent);
Node* parent = node->parentNode();
- // A script may have removed the current node's parent from the DOM
- // http://bugs.webkit.org/show_bug.cgi?id=7137
- // FIXME: we should do real recovery here and re-parent with the correct node.
if (!parent)
return false;
- Node* grandparent = parent->parentNode();
-
- if (n->isTextNode() ||
- (h->hasLocalName(trTag) &&
- isTableSection(parent) && grandparent->hasTagName(tableTag)) ||
- ((!n->hasTagName(tdTag) && !n->hasTagName(thTag) &&
- !n->hasTagName(formTag) && !n->hasTagName(scriptTag)) && isTableSection(node) &&
- parent->hasTagName(tableTag))) {
- node = (node->hasTagName(tableTag)) ? node :
- ((node->hasTagName(trTag)) ? grandparent : parent);
- Node* parent = node->parentNode();
- if (!parent)
- return false;
- parent->insertBefore(n, node, ec);
- if (!ec) {
- reportError(StrayTableContentError, &localName, ¤tTagName);
- if (n->isHTMLElement() && tagPriority > 0 &&
- !flat && static_cast<HTMLElement*>(n)->endTagRequirement() != TagStatusForbidden)
- {
- pushBlock(localName, tagPriority);
- setCurrent(n);
- inStrayTableContent++;
- blockStack->strayTableContent = true;
- }
- return true;
- }
- }
-
+ parent->insertBefore(n, node, ec);
if (!ec) {
- if (current->hasTagName(trTag)) {
- reportError(TablePartRequiredError, &localName, &tdTag.localName());
- e = new HTMLTableCellElement(tdTag, document);
- } else if (current->hasTagName(tableTag)) {
- // Don't report an error in this case, since making a <tbody> happens all the time when you have <table><tr>,
- // and it isn't really a parse error per se.
- e = new HTMLTableSectionElement(tbodyTag, document);
- } else {
- reportError(TablePartRequiredError, &localName, &trTag.localName());
- e = new HTMLTableRowElement(document);
+ reportError(StrayTableContentError, &localName, ¤tTagName);
+ if (n->isHTMLElement() && tagPriority > 0 &&
+ !flat && static_cast<HTMLElement*>(n)->endTagRequirement() != TagStatusForbidden)
+ {
+ pushBlock(localName, tagPriority);
+ setCurrent(n);
+ inStrayTableContent++;
+ blockStack->strayTableContent = true;
}
-
- insertNode(e);
- handled = true;
+ return true;
}
}
+
+ if (!ec) {
+ if (current->hasTagName(trTag)) {
+ reportError(TablePartRequiredError, &localName, &tdTag.localName());
+ e = new HTMLTableCellElement(tdTag, document);
+ } else if (current->hasTagName(tableTag)) {
+ // Don't report an error in this case, since making a <tbody> happens all the time when you have <table><tr>,
+ // and it isn't really a parse error per se.
+ e = new HTMLTableSectionElement(tbodyTag, document);
+ } else {
+ reportError(TablePartRequiredError, &localName, &trTag.localName());
+ e = new HTMLTableRowElement(document);
+ }
+
+ insertNode(e);
+ handled = true;
+ }
}
} else if (h->hasLocalName(objectTag)) {
reportError(BadObjectContentError, &localName);
@@ -577,10 +563,8 @@
popBlock(localName);
}
} else if (h->hasLocalName(colgroupTag)) {
- if (!n->isTextNode()) {
- popBlock(currentTagName);
- handled = true;
- }
+ popBlock(currentTagName);
+ handled = true;
} else if (!h->hasLocalName(bodyTag)) {
if (isInline(current)) {
popInlineBlocks();
diff --git a/WebCore/html/HTMLTableColElement.cpp b/WebCore/html/HTMLTableColElement.cpp
index be59953..2a17c0b 100644
--- a/WebCore/html/HTMLTableColElement.cpp
+++ b/WebCore/html/HTMLTableColElement.cpp
@@ -30,6 +30,7 @@
#include "HTMLNames.h"
#include "RenderTableCol.h"
#include "HTMLTableElement.h"
+#include "Text.h"
namespace WebCore {
@@ -53,7 +54,12 @@
bool HTMLTableColElement::checkDTD(const Node* newChild)
{
- return hasLocalName(colgroupTag) && newChild->hasTagName(colTag);
+ if (hasLocalName(colTag))
+ return false;
+
+ if (newChild->isTextNode())
+ return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
+ return newChild->hasTagName(colTag);
}
bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
diff --git a/WebCore/html/HTMLTableElement.cpp b/WebCore/html/HTMLTableElement.cpp
index 00d6a31..8c67bba 100644
--- a/WebCore/html/HTMLTableElement.cpp
+++ b/WebCore/html/HTMLTableElement.cpp
@@ -37,6 +37,7 @@
#include "HTMLTableCaptionElement.h"
#include "HTMLTableSectionElement.h"
#include "RenderTable.h"
+#include "Text.h"
namespace WebCore {
@@ -64,7 +65,9 @@
bool HTMLTableElement::checkDTD(const Node* newChild)
{
- return newChild->isTextNode() || newChild->hasTagName(captionTag) ||
+ if (newChild->isTextNode())
+ return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
+ return newChild->hasTagName(captionTag) ||
newChild->hasTagName(colTag) || newChild->hasTagName(colgroupTag) ||
newChild->hasTagName(theadTag) || newChild->hasTagName(tfootTag) ||
newChild->hasTagName(tbodyTag) || newChild->hasTagName(formTag) ||
diff --git a/WebCore/html/HTMLTableRowElement.cpp b/WebCore/html/HTMLTableRowElement.cpp
index 94fcee1..d476e42 100644
--- a/WebCore/html/HTMLTableRowElement.cpp
+++ b/WebCore/html/HTMLTableRowElement.cpp
@@ -33,6 +33,7 @@
#include "HTMLTableElement.h"
#include "HTMLTableSectionElement.h"
#include "NodeList.h"
+#include "Text.h"
namespace WebCore {
@@ -45,6 +46,8 @@
bool HTMLTableRowElement::checkDTD(const Node* newChild)
{
+ if (newChild->isTextNode())
+ return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
return newChild->hasTagName(tdTag) || newChild->hasTagName(thTag) ||
newChild->hasTagName(formTag) || newChild->hasTagName(scriptTag);
}
diff --git a/WebCore/html/HTMLTableSectionElement.cpp b/WebCore/html/HTMLTableSectionElement.cpp
index 3b5abd0..d5ce785 100644
--- a/WebCore/html/HTMLTableSectionElement.cpp
+++ b/WebCore/html/HTMLTableSectionElement.cpp
@@ -32,6 +32,7 @@
#include "HTMLTableRowElement.h"
#include "HTMLTableElement.h"
#include "NodeList.h"
+#include "Text.h"
namespace WebCore {
@@ -44,6 +45,8 @@
bool HTMLTableSectionElement::checkDTD(const Node* newChild)
{
+ if (newChild->isTextNode())
+ return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
return newChild->hasTagName(trTag) || newChild->hasTagName(formTag) ||
newChild->hasTagName(scriptTag);
}