From effc175afda3044f84588e9bd3fedbb8b3f7ffef Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Fri, 18 Mar 2005 06:56:56 +0000 Subject: [PATCH] Handle unterminated strings in CSS by using an additional error token type. b=286262 r+sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@170886 18797224-902f-48f8-a5cc-f745e15eee43 --- .../en-US/chrome/layout/css.properties | 1 + mozilla/layout/style/nsCSSScanner.cpp | 29 +++++++------ mozilla/layout/style/nsCSSScanner.h | 43 ++++++++++--------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/mozilla/dom/locales/en-US/chrome/layout/css.properties b/mozilla/dom/locales/en-US/chrome/layout/css.properties index ec0c5c9fe77..e5725cf4d34 100644 --- a/mozilla/dom/locales/en-US/chrome/layout/css.properties +++ b/mozilla/dom/locales/en-US/chrome/layout/css.properties @@ -127,3 +127,4 @@ PEBadDeclEnd=Expected ';' to terminate declaration but found '%1$S'. PEBadDeclOrRuleEnd=Expected ';' or '}' to terminate declaration but found '%1$S'. PEInaccessibleProperty=Attempt to use inaccessible property PECommentEOF=end of comment +SEUnterminatedString=Found unclosed string '%1$S'. diff --git a/mozilla/layout/style/nsCSSScanner.cpp b/mozilla/layout/style/nsCSSScanner.cpp index 28bdb8fe5ff..ca711630d1f 100644 --- a/mozilla/layout/style/nsCSSScanner.cpp +++ b/mozilla/layout/style/nsCSSScanner.cpp @@ -166,7 +166,10 @@ nsCSSToken::AppendToString(nsString& aBuffer) case eCSSToken_Dashmatch: aBuffer.AppendLiteral("|="); break; - + case eCSSToken_Error: + aBuffer.Append(mSymbol); + aBuffer.Append(mIdent); + break; default: NS_ERROR("invalid token type"); break; @@ -1073,12 +1076,19 @@ PRBool nsCSSScanner::ParseEOLComment(nsresult& aErrorCode, nsCSSToken& aToken) } #endif // 0 -PRBool nsCSSScanner::GatherString(nsresult& aErrorCode, PRInt32 aStop, - nsString& aBuffer) +PRBool nsCSSScanner::ParseString(nsresult& aErrorCode, PRInt32 aStop, + nsCSSToken& aToken) { + aToken.mIdent.SetLength(0); + aToken.mType = eCSSToken_String; + aToken.mSymbol = PRUnichar(aStop); // remember how it's quoted for (;;) { if (EatNewline(aErrorCode)) { - return PR_FALSE; + aToken.mType = eCSSToken_Error; +#ifdef CSS_REPORT_PARSE_ERRORS + ReportUnexpectedToken(aToken, "SEUnterminatedString"); +#endif + return PR_TRUE; } PRInt32 ch = Read(aErrorCode); if (ch < 0) { @@ -1094,17 +1104,8 @@ PRBool nsCSSScanner::GatherString(nsresult& aErrorCode, PRInt32 aStop, } } if (0 < ch) { - aBuffer.Append(PRUnichar(ch)); + aToken.mIdent.Append(PRUnichar(ch)); } } return PR_TRUE; } - -PRBool nsCSSScanner::ParseString(nsresult& aErrorCode, PRInt32 aStop, - nsCSSToken& aToken) -{ - aToken.mIdent.SetLength(0); - aToken.mType = eCSSToken_String; - aToken.mSymbol = PRUnichar(aStop); // remember how it's quoted - return GatherString(aErrorCode, aStop, aToken.mIdent); -} diff --git a/mozilla/layout/style/nsCSSScanner.h b/mozilla/layout/style/nsCSSScanner.h index 2c981100372..1425afb1070 100644 --- a/mozilla/layout/style/nsCSSScanner.h +++ b/mozilla/layout/style/nsCSSScanner.h @@ -53,42 +53,45 @@ class nsIURI; // Token types enum nsCSSTokenType { // A css identifier (e.g. foo) - eCSSToken_Ident = 0, // mIdent + eCSSToken_Ident, // mIdent // A css at keyword (e.g. @foo) - eCSSToken_AtKeyword = 1, // mIdent + eCSSToken_AtKeyword, // mIdent // A css number without a percentage or dimension; with percentage; // without percentage but with a dimension - eCSSToken_Number = 2, // mNumber - eCSSToken_Percentage = 3, // mNumber - eCSSToken_Dimension = 4, // mNumber + mIdent + eCSSToken_Number, // mNumber + eCSSToken_Percentage, // mNumber + eCSSToken_Dimension, // mNumber + mIdent // A css string (e.g. "foo" or 'foo') - eCSSToken_String = 5, // mSymbol + mIdent + mSymbol + eCSSToken_String, // mSymbol + mIdent + mSymbol // Whitespace (e.g. " " or "/* abc */") - eCSSToken_WhiteSpace = 6, // mIdent + eCSSToken_WhiteSpace, // mIdent // A css symbol (e.g. ':', ';', '+', etc.) - eCSSToken_Symbol = 7, // mSymbol + eCSSToken_Symbol, // mSymbol // A css1 id (e.g. #foo3) - eCSSToken_ID = 8, // mIdent + eCSSToken_ID, // mIdent - eCSSToken_Function = 9, // mIdent + eCSSToken_Function, // mIdent - eCSSToken_URL = 10, // mIdent - eCSSToken_InvalidURL = 11, // doesn't matter + eCSSToken_URL, // mIdent + eCSSToken_InvalidURL, // doesn't matter - eCSSToken_HTMLComment = 12, // "" + eCSSToken_HTMLComment, // "" - eCSSToken_Includes = 13, // "~=" - eCSSToken_Dashmatch = 14, // "|=" - eCSSToken_Beginsmatch = 15, // "^=" - eCSSToken_Endsmatch = 16, // "$=" - eCSSToken_Containsmatch = 17 // "*=" + eCSSToken_Includes, // "~=" + eCSSToken_Dashmatch, // "|=" + eCSSToken_Beginsmatch, // "^=" + eCSSToken_Endsmatch, // "$=" + eCSSToken_Containsmatch, // "*=" + // A special token indicating that there was an error in tokenization. + // It's always an unterminated string. + eCSSToken_Error // mSymbol + mIdent }; struct nsCSSToken { @@ -156,7 +159,7 @@ class nsCSSScanner { PRUint32 GetLineNumber() { return mLineNumber; } - // Get the next token. Return nsfalse on EOF or ERROR. aTokenResult + // Get the next token. Return PR_FALSE on EOF. aTokenResult // is filled in with the data for the token. PRBool Next(nsresult& aErrorCode, nsCSSToken& aTokenResult); @@ -204,8 +207,6 @@ protected: #endif PRBool SkipCComment(nsresult& aErrorCode); - PRBool GatherString(nsresult& aErrorCode, PRInt32 aStop, - nsString& aString); PRBool GatherIdent(nsresult& aErrorCode, PRInt32 aChar, nsString& aIdent); nsCOMPtr mInput;