From d6699c6c57e0b7d3adaa237db7b8c27d174e7800 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Sat, 23 Mar 2002 01:18:52 +0000 Subject: [PATCH] Bug 132785, regression in strict comment parsing. Although spec does not allow non-whitespace characters between last dash and greater than, there seem to be lots of pages out there that do this. Relax the code that detects comment end so this starts working again. r=harishd, sr=jst, a=asa. git-svn-id: svn://10.0.0.236/trunk@117272 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/nsHTMLTokens.cpp | 15 +++++++++------ mozilla/parser/htmlparser/src/nsHTMLTokens.cpp | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mozilla/htmlparser/src/nsHTMLTokens.cpp b/mozilla/htmlparser/src/nsHTMLTokens.cpp index 0ee9b3e17e3..9cc2d0d7696 100644 --- a/mozilla/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokens.cpp @@ -1006,21 +1006,24 @@ CCommentToken::CCommentToken(const nsAReadableString& aName) : CHTMLToken(eHTMLT mTextValue.Assign(aName); } -// We must test if we have whitespace and > -static PRBool IsGoodCommentEnd( +static PRBool IsCommentEnd( const nsReadingIterator& aCurrent, const nsReadingIterator& aEnd, nsReadingIterator& aGt) { nsReadingIterator current = aCurrent; + PRInt32 dashes = 0; - while (current != aEnd) { + while ((current != aEnd) && (dashes != 2)) { if (*current == kGreaterThan) { aGt = current; return PR_TRUE; } - if (!nsString::IsSpace(*current)) - break; + if (*current == PRUnichar('-')) { + dashes++; + } else { + dashes = 0; + } ++current; } @@ -1053,7 +1056,7 @@ nsresult ConsumeStrictComment(nsScanner& aScanner, nsString& aString) { } balancedComment = !balancedComment; // We need to match '--' with '--' - if (balancedComment && IsGoodCommentEnd(current, end, gt)) { + if (balancedComment && IsCommentEnd(current, end, gt)) { // done current.advance(-2); if (beginData != current) { // protects from diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp index 0ee9b3e17e3..9cc2d0d7696 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp @@ -1006,21 +1006,24 @@ CCommentToken::CCommentToken(const nsAReadableString& aName) : CHTMLToken(eHTMLT mTextValue.Assign(aName); } -// We must test if we have whitespace and > -static PRBool IsGoodCommentEnd( +static PRBool IsCommentEnd( const nsReadingIterator& aCurrent, const nsReadingIterator& aEnd, nsReadingIterator& aGt) { nsReadingIterator current = aCurrent; + PRInt32 dashes = 0; - while (current != aEnd) { + while ((current != aEnd) && (dashes != 2)) { if (*current == kGreaterThan) { aGt = current; return PR_TRUE; } - if (!nsString::IsSpace(*current)) - break; + if (*current == PRUnichar('-')) { + dashes++; + } else { + dashes = 0; + } ++current; } @@ -1053,7 +1056,7 @@ nsresult ConsumeStrictComment(nsScanner& aScanner, nsString& aString) { } balancedComment = !balancedComment; // We need to match '--' with '--' - if (balancedComment && IsGoodCommentEnd(current, end, gt)) { + if (balancedComment && IsCommentEnd(current, end, gt)) { // done current.advance(-2); if (beginData != current) { // protects from