Commit 94376177 authored by hyatt's avatar hyatt

Add error reporting for the </p> -> <p></p> quirk.

        Add error reporting when a stray close tag is encountered with no
        corresponding open tag.

        Reviewed by adele

        * html/HTMLParser.cpp:
        (WebCore::HTMLParser::HTMLParser):
        (WebCore::HTMLParser::processCloseTag):
        (WebCore::HTMLParser::popBlock):
        * html/HTMLParser.h:
        (WebCore::HTMLParser::popBlock):
        * html/HTMLParserErrorCodes.cpp:
        (WebCore::htmlParserErrorMessageTemplate):
        * html/HTMLParserErrorCodes.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21726 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0a2e43eb
2007-05-24 David Hyatt <hyatt@apple.com>
Add error reporting for the </p> -> <p></p> quirk.
Add error reporting when a stray close tag is encountered with no
corresponding open tag.
Reviewed by adele
* html/HTMLParser.cpp:
(WebCore::HTMLParser::HTMLParser):
(WebCore::HTMLParser::processCloseTag):
(WebCore::HTMLParser::popBlock):
* html/HTMLParser.h:
(WebCore::HTMLParser::popBlock):
* html/HTMLParserErrorCodes.cpp:
(WebCore::htmlParserErrorMessageTemplate):
* html/HTMLParserErrorCodes.h:
2007-05-24 Kevin McCullough <kmccullough@apple.com>
Reviewed by.
......@@ -822,7 +822,7 @@ void HTMLParser::processCloseTag(Token* t)
// Support for really broken html.
// we never close the body tag, since some stupid web pages close it before the actual end of the doc.
// let's rely on the end() call to close things.
if (t->tagName == htmlTag || t->tagName == bodyTag)
if (t->tagName == htmlTag || t->tagName == bodyTag || t->tagName == commentAtom)
return;
if (t->tagName == formTag)
......@@ -831,7 +831,7 @@ void HTMLParser::processCloseTag(Token* t)
m_currentMapElement = 0;
HTMLStackElem* oldElem = blockStack;
popBlock(t->tagName);
popBlock(t->tagName, true);
if (oldElem == blockStack && t->tagName == pTag) {
// We encountered a stray </p>. Amazingly Gecko, WinIE, and MacIE all treat
// this as a valid break, i.e., <p></p>. So go ahead and make the empty
......@@ -839,6 +839,7 @@ void HTMLParser::processCloseTag(Token* t)
t->beginTag = true;
parseToken(t);
popBlock(t->tagName);
reportError(StrayParagraphCloseError);
}
}
......@@ -1192,7 +1193,7 @@ void HTMLParser::pushBlock(const AtomicString& tagName, int level)
didRefCurrent = false;
}
void HTMLParser::popBlock(const AtomicString& tagName)
void HTMLParser::popBlock(const AtomicString& tagName, bool reportErrors)
{
HTMLStackElem* elem = blockStack;
......@@ -1204,8 +1205,11 @@ void HTMLParser::popBlock(const AtomicString& tagName)
elem = elem->next;
}
if (!elem)
if (!elem) {
if (reportErrors)
reportError(StrayCloseTagError, &tagName);
return;
}
if (maxLevel > elem->level) {
// We didn't match because the tag is in a different scope, e.g.,
......@@ -1397,7 +1401,7 @@ void HTMLParser::finished()
document->finishedParsing();
}
void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const AtomicString* tagName1, const AtomicString* tagName2)
void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const AtomicString* tagName1, const AtomicString* tagName2, bool closeTags)
{
Frame* frame = document->frame();
if (!frame)
......@@ -1418,7 +1422,7 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
else if (*tagName1 == "#comment")
tag1 = "<!-- comment -->";
else
tag1 = "<" + *tagName1 + ">";
tag1 = (closeTags ? "</" : "<") + *tagName1 + ">";
}
if (tagName2) {
if (*tagName2 == "#text")
......@@ -1426,7 +1430,7 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
else if (*tagName2 == "#comment")
tag2 = "<!-- comment -->";
else
tag2 = "<" + *tagName2 + ">";
tag2 = (closeTags ? "</" : "<") + *tagName2 + ">";
}
const char* errorMsg = htmlParserErrorMessageTemplate(errorCode);
......
......@@ -103,8 +103,8 @@ private:
bool handleError(Node*, bool flat, const AtomicString& localName, int tagPriority);
void pushBlock(const AtomicString& tagName, int level);
void popBlock(const AtomicString& tagName);
void popBlock(const QualifiedName& qName) { return popBlock(qName.localName()); } // Convenience function for readability.
void popBlock(const AtomicString& tagName, bool reportErrors = false);
void popBlock(const QualifiedName& qName, bool reportErrors = false) { return popBlock(qName.localName(), reportErrors); } // Convenience function for readability.
void popOneBlock();
void moveOneBlockToStack(HTMLStackElem*& head);
inline HTMLStackElem* popOneBlockCommon();
......@@ -129,10 +129,10 @@ private:
void startBody(); // inserts the isindex element
PassRefPtr<Node> handleIsindex(Token*);
void reportError(HTMLParserErrorCode errorCode, const AtomicString* tagName1 = 0, const AtomicString* tagName2 = 0)
{ if (!m_reportErrors) return; reportErrorToConsole(errorCode, tagName1, tagName2); }
void reportError(HTMLParserErrorCode errorCode, const AtomicString* tagName1 = 0, const AtomicString* tagName2 = 0, bool closeTags = false)
{ if (!m_reportErrors) return; reportErrorToConsole(errorCode, tagName1, tagName2, closeTags); }
void reportErrorToConsole(HTMLParserErrorCode, const AtomicString* tagName1, const AtomicString* tagName2);
void reportErrorToConsole(HTMLParserErrorCode, const AtomicString* tagName1, const AtomicString* tagName2, bool closeTags);
Document* document;
......
......@@ -44,10 +44,12 @@ const char* htmlParserErrorMessageTemplate(HTMLParserErrorCode errorCode)
"%tag1 is not allowed inside %tag2. Inserting %tag1 before the <table> instead.",
"%tag1 misplaced in <table>. Creating %tag2 and putting %tag1 inside it.",
"</br> encountered. Converting </br> into <br>.",
"XML self-closing tag syntax used on %tag1. The tag will not be closed."
"XML self-closing tag syntax used on %tag1. The tag will not be closed.",
"Stray </p> encountered. Converting </p> into <p></p>.",
"Stray %tag1 encountered. Ignoring close tag."
};
if (errorCode >= MisplacedTablePartError && errorCode <= TablePartRequiredError)
if (errorCode >= MisplacedTablePartError && errorCode <= StrayCloseTagError)
return errors[errorCode];
return 0;
}
......
......@@ -42,7 +42,9 @@ enum HTMLParserErrorCode {
StrayTableContentError,
TablePartRequiredError,
MalformedBRError,
IncorrectXMLSelfCloseError
IncorrectXMLSelfCloseError,
StrayParagraphCloseError,
StrayCloseTagError
};
const char* htmlParserErrorMessageTemplate(HTMLParserErrorCode);
......
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