Bug 814566 - Allow invalid syntax (with balanced parentheses) inside @supports conditions. (v1.1.1) r=dbaron

This commit is contained in:
Cameron McCormack 2012-12-23 13:30:55 +11:00
Родитель beb64f76b4
Коммит 6550289df6
17 изменённых файлов: 262 добавлений и 35 удалений

Просмотреть файл

@ -12,7 +12,7 @@ PEDeclSkipped=Skipped to next declaration.
PEUnknownProperty=Unknown property '%1$S'.
PEValueParsingError=Error in parsing value for '%1$S'.
PEExpectEndValue=Expected end of value but found '%1$S'.
PESkipAtRuleEOF=end of unknown at-rule
PESkipAtRuleEOF2=end of at-rule
PEUnknownAtRule=Unrecognized at-rule or error parsing at-rule '%1$S'.
PECharsetRuleEOF=charset string in @charset rule
PECharsetRuleNotString=Expected charset string but found '%1$S'.
@ -115,11 +115,11 @@ PEBadFontBlockStart=Expected '{' to begin @font-face rule but found '%1$S'.
PEBadFontBlockEnd=Expected '}' to end @font-face rule but found '%1$S'.
PEAnonBoxNotAlone=Did not expect anonymous box.
PEBadDirValue=Expected 'ltr' or 'rtl' in direction selector but found '%1$S'.
PESupportsConditionStartEOF='not' or '('
PESupportsConditionInParensStartEOF='not', '(' or identifier
PESupportsConditionStartEOF2='not', '(', or function
PESupportsConditionInParensEOF=')'
PESupportsConditionNotEOF='not'
PESupportsConditionExpectedOpenParen=Expected '(' while parsing supports condition but found '%1$S'.
PESupportsConditionExpectedOpenParenOrFunction=Expected '(' or function while parsing supports condition but found '%1$S'.
PESupportsConditionExpectedCloseParen=Expected ')' while parsing supports condition but found '%1$S'.
PESupportsConditionExpectedStart=Expected 'not' or '(' while parsing supports condition but found '%1$S'.
PESupportsConditionExpectedStart2=Expected 'not', '(', or function while parsing supports condition but found '%1$S'.
PESupportsConditionExpectedNot=Expected 'not' while parsing supports condition but found '%1$S'.
PESupportsGroupRuleStart=Expected '{' to begin @supports rule but found '%1$S'.

Просмотреть файл

@ -5,7 +5,7 @@
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="There need not be any white space between the '@supports' and open brace of the rule set, not between a declaration's property name and value."/>
<meta name="assert" content="There need not be any white space between the '@supports' and open brace of the rule set, nor between a declaration's property name and value."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
@supports(color:green){

Просмотреть файл

@ -1,16 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with invalid syntax must not apply rules inside it</title>
<title>CSS Test: An @supports rule with balanced invalid syntax within parentheses must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="An @supports conditions must fail to parse if a declaration has an empy property value."/>
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse even if a declaration has an empty property value."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
html { background-color: red }
@supports (unknown:) or (color: green) {
html { background-color: red }
html { background-color: green }
}
]]></style>
</head>

Просмотреть файл

@ -1,16 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with invalid syntax must not apply rules inside it</title>
<title>CSS Test: An @supports rule with balanced invalid syntax within parentheses must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="A property declaration in an @supports declaration must not omit the colon between the property name and value."/>
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse a parenthesized expression that has invalid syntax with balanced parentheses."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
html { background-color: red }
@supports (unknown) or (color: green) {
html { background-color: red }
html { background-color: green }
}
]]></style>
</head>

Просмотреть файл

@ -1,16 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with invalid syntax must not apply rules inside it</title>
<title>CSS Test: An @supports rule with balanced invalid syntax within parentheses must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="An @supports conditions must fail to parse if a declaration has an empy property value."/>
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse a parenthesized expression that has invalid syntax with balanced parentheses."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
html { background-color: red }
@supports (color:) or (color: green) {
html { background-color: red }
html { background-color: green }
}
]]></style>
</head>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with balanced invalid syntax must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse and evaluate to false a parenthesized expression has invalid syntax."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: red }
@supports not (@page) {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with balanced invalid syntax must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse a parenthesized expression that has invalid syntax with balanced parentheses."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: red }
@supports not ({ something @with [ balanced ] parens }) {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with balanced invalid syntax must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition must successfully parse a parenthesized expression that has invalid syntax with balanced parentheses."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: red }
@supports not ({ something @with [ balanced ] parens }) {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with unbalanced invalid syntax must fail to parse</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="An @supports condition with a parenthesized expression that has unbalanced parentheses must fail to parse."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
@supports not ({ something @with (unbalanced parens }) {
html { background-color: red }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with an unrecognized condition using functional notation must evaluate to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition with an unrecognized condition using functional notation must evaluate to false."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: red }
@supports an-extension(of some kind) or (color: green) {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule with an unrecognized condition using functional notation with unbalanced parentheses must fail to parse</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="An @supports condition with an unrecognized condition using functional notation with unbalanced parentheses must fail to parse."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
@supports (color: green) or an-extension(that is [unbalanced) {
html { background-color: red }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: In an @supports rule "not(" must be parsed as a FUNCTION</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports condition with 'not(' must parse be parsed as a FUNCTION token."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
@supports not(unknown: unknown) {
html { background-color: red }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: In an @supports rule "or(" must be parsed as a FUNCTION</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="invalid" />
<meta name="assert" content="An @supports condition with 'or(' must parse be parsed as a FUNCTION token."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
html { background-color: green }
@supports (color: green) or(color: blue) {
html { background-color: red }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule condition with empty parentheses should evaluates to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports rule condition that consists just of a pair of parentheses should evaluate to false."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
@supports not () {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -0,0 +1,18 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Test: An @supports rule condition with empty parentheses should evaluates to false</title>
<link rel="author" title="Cameron McCormack" href="mailto:cam@mcc.id.au" />
<link rel="help" href="http://www.w3.org/TR/css3-conditional/#at-supports" />
<meta name="flags" content="" />
<meta name="assert" content="An @supports rule condition that consists just of a pair of parentheses should evaluate to false."/>
<link rel="match" href="support/pass.xht" />
<style type="text/css"><![CDATA[
@supports () or (color: green) {
html { background-color: green }
}
]]></style>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -31,3 +31,13 @@ default-preferences pref(layout.css.supports-rule.enabled,true)
== css-supports-029.xht support/pass.xht
== css-supports-030.xht support/pass.xht
== css-supports-031.xht support/pass.xht
== css-supports-032.xht support/pass.xht
== css-supports-033.xht support/pass.xht
== css-supports-034.xht support/pass.xht
== css-supports-035.xht support/pass.xht
== css-supports-036.xht support/pass.xht
== css-supports-037.xht support/pass.xht
== css-supports-038.xht support/pass.xht
== css-supports-039.xht support/pass.xht
== css-supports-040.xht support/pass.xht
== css-supports-041.xht support/pass.xht

Просмотреть файл

@ -342,8 +342,11 @@ protected:
bool ExpectEndProperty();
bool CheckEndProperty();
nsSubstring* NextIdent();
void SkipUntil(PRUnichar aStopSymbol);
// returns true when the stop symbol is found, and false for EOF
bool SkipUntil(PRUnichar aStopSymbol);
void SkipUntilOneOf(const PRUnichar* aStopSymbolChars);
void SkipRuleSet(bool aInsideBraces);
bool SkipAtRule(bool aInsideBlock);
bool SkipDeclaration(bool aCheckForBraces);
@ -1505,7 +1508,7 @@ CSSParserImpl::SkipAtRule(bool aInsideBlock)
{
for (;;) {
if (!GetToken(true)) {
REPORT_UNEXPECTED_EOF(PESkipAtRuleEOF);
REPORT_UNEXPECTED_EOF(PESkipAtRuleEOF2);
return false;
}
if (eCSSToken_Symbol == mToken.mType) {
@ -2460,13 +2463,16 @@ bool
CSSParserImpl::ParseSupportsCondition(bool& aConditionMet)
{
if (!GetToken(true)) {
REPORT_UNEXPECTED_EOF(PESupportsConditionStartEOF);
REPORT_UNEXPECTED_EOF(PESupportsConditionStartEOF2);
return false;
}
UngetToken();
if (mToken.IsSymbol('(')) {
if (mToken.IsSymbol('(') ||
mToken.mType == eCSSToken_Function ||
mToken.mType == eCSSToken_URL ||
mToken.mType == eCSSToken_Bad_URL) {
return ParseSupportsConditionInParens(aConditionMet) &&
ParseSupportsConditionTerms(aConditionMet);
}
@ -2507,18 +2513,44 @@ CSSParserImpl::ParseSupportsConditionNegation(bool& aConditionMet)
// supports_condition_in_parens
// : '(' S* supports_condition_in_parens_inside_parens ')' S*
// | general_enclosed
// ;
bool
CSSParserImpl::ParseSupportsConditionInParens(bool& aConditionMet)
{
if (!ExpectSymbol('(', true)) {
REPORT_UNEXPECTED_TOKEN(PESupportsConditionExpectedOpenParen);
if (!GetToken(true)) {
REPORT_UNEXPECTED_EOF(PESupportsConditionInParensStartEOF);
return false;
}
if (mToken.mType == eCSSToken_URL) {
aConditionMet = false;
return true;
}
if (mToken.mType == eCSSToken_Function ||
mToken.mType == eCSSToken_Bad_URL) {
if (!SkipUntil(')')) {
REPORT_UNEXPECTED_EOF(PESupportsConditionInParensEOF);
return false;
}
aConditionMet = false;
return true;
}
if (!mToken.IsSymbol('(')) {
REPORT_UNEXPECTED_TOKEN(PESupportsConditionExpectedOpenParenOrFunction);
UngetToken();
return false;
}
if (!ParseSupportsConditionInParensInsideParens(aConditionMet)) {
SkipUntil(')');
return false;
if (!SkipUntil(')')) {
REPORT_UNEXPECTED_EOF(PESupportsConditionInParensEOF);
return false;
}
aConditionMet = false;
return true;
}
if (!(ExpectSymbol(')', true))) {
@ -2539,7 +2571,6 @@ bool
CSSParserImpl::ParseSupportsConditionInParensInsideParens(bool& aConditionMet)
{
if (!GetToken(true)) {
REPORT_UNEXPECTED_EOF(PESupportsConditionInParensStartEOF);
return false;
}
@ -2547,12 +2578,10 @@ CSSParserImpl::ParseSupportsConditionInParensInsideParens(bool& aConditionMet)
if (!mToken.mIdent.LowerCaseEqualsLiteral("not")) {
nsAutoString propertyName = mToken.mIdent;
if (!ExpectSymbol(':', true)) {
REPORT_UNEXPECTED_TOKEN(PEParseDeclarationNoColon);
return false;
}
if (ExpectSymbol(')', true)) {
REPORT_UNEXPECTED_P(PEValueParsingError, propertyName);
UngetToken();
return false;
}
@ -2643,7 +2672,7 @@ CSSParserImpl::ParseSupportsConditionTermsAfterOperator(
}
}
void
bool
CSSParserImpl::SkipUntil(PRUnichar aStopSymbol)
{
nsCSSToken* tk = &mToken;
@ -2651,7 +2680,7 @@ CSSParserImpl::SkipUntil(PRUnichar aStopSymbol)
stack.AppendElement(aStopSymbol);
for (;;) {
if (!GetToken(true)) {
break;
return false;
}
if (eCSSToken_Symbol == tk->mType) {
PRUnichar symbol = tk->mSymbol;
@ -2659,7 +2688,7 @@ CSSParserImpl::SkipUntil(PRUnichar aStopSymbol)
if (symbol == stack.ElementAt(stackTopIndex)) {
stack.RemoveElementAt(stackTopIndex);
if (stackTopIndex == 0) {
break;
return true;
}
// Just handle out-of-memory by parsing incorrectly. It's