From b3e769bbad0a0cf2a96b807cd8f248eef33f1974 Mon Sep 17 00:00:00 2001 From: hyatt Date: Fri, 15 Apr 2005 20:36:16 +0000 Subject: [PATCH] Fix for row 13 of the Acid2 test. Change HTML comment parsing in strict mode to do proper SGML parsing, checking for pairs of -- and only being willing to close the comment if every -- is paired up. * khtml/html/htmltokenizer.cpp: (khtml::HTMLTokenizer::parseComment): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9020 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog-2005-08-23 | 8 ++++++ WebCore/khtml/html/htmltokenizer.cpp | 39 +++++++++++++++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23 index 9c63fe9d777b..b05b03b3ebd7 100644 --- a/WebCore/ChangeLog-2005-08-23 +++ b/WebCore/ChangeLog-2005-08-23 @@ -1,3 +1,11 @@ +2005-04-15 David Hyatt + + Fix for row 13 of the Acid2 test. Change HTML comment parsing in strict mode to do proper SGML parsing, + checking for pairs of -- and only being willing to close the comment if every -- is paired up. + + * khtml/html/htmltokenizer.cpp: + (khtml::HTMLTokenizer::parseComment): + 2005-04-12 Maciej Stachowiak Reviewed by Richard. diff --git a/WebCore/khtml/html/htmltokenizer.cpp b/WebCore/khtml/html/htmltokenizer.cpp index cbb60a0be24c..2141d5681c1f 100644 --- a/WebCore/khtml/html/htmltokenizer.cpp +++ b/WebCore/khtml/html/htmltokenizer.cpp @@ -657,6 +657,9 @@ void HTMLTokenizer::scriptExecution( const QString& str, QString scriptURL, void HTMLTokenizer::parseComment(TokenizerString &src) { + bool strict = !parser->doc()->inCompatMode(); + int delimiterCount = 0; + bool canClose = false; checkScriptBuffer(src.length()); while ( !src.isEmpty() ) { scriptCode[ scriptCodeSize++ ] = *src; @@ -664,19 +667,35 @@ void HTMLTokenizer::parseComment(TokenizerString &src) qDebug("comment is now: *%s*", QConstString((QChar*)src.current(), QMIN(16, src.length())).string().latin1()); #endif - if (src->unicode() == '>') { + + if (strict) { + if (src->unicode() == '-') { + delimiterCount++; + if (delimiterCount == 2) { + delimiterCount = 0; + canClose = !canClose; + } + } + else + delimiterCount = 0; + } + + if ((!strict || canClose) && src->unicode() == '>') { bool handleBrokenComments = brokenComments && !(script || style); int endCharsCount = 1; // start off with one for the '>' character - if (scriptCodeSize > 2 && scriptCode[scriptCodeSize-3] == '-' && scriptCode[scriptCodeSize-2] == '-') { - endCharsCount = 3; - } - else if (scriptCodeSize > 3 && scriptCode[scriptCodeSize-4] == '-' && scriptCode[scriptCodeSize-3] == '-' && - scriptCode[scriptCodeSize-2] == '!') { - // Other browsers will accept --!> as a close comment, even though it's - // not technically valid. - endCharsCount = 4; + if (!strict) { + // In quirks mode just check for --> + if (scriptCodeSize > 2 && scriptCode[scriptCodeSize-3] == '-' && scriptCode[scriptCodeSize-2] == '-') { + endCharsCount = 3; + } + else if (scriptCodeSize > 3 && scriptCode[scriptCodeSize-4] == '-' && scriptCode[scriptCodeSize-3] == '-' && + scriptCode[scriptCodeSize-2] == '!') { + // Other browsers will accept --!> as a close comment, even though it's + // not technically valid. + endCharsCount = 4; + } } - if (handleBrokenComments || endCharsCount > 1) { + if (canClose || handleBrokenComments || endCharsCount > 1) { ++src; if (!( script || xmp || textarea || style)) { if (includesCommentsInDOM) { -- 2.36.0