Correct handling of unitless zero in calc() expressions. (Bug 595648) r=bzbarsky a=blocking2.0:betaN+

This ensures that we treat a unitless zero as a number rather than a
length inside of calc() expressions.  This causes both the acceptance of
previously-rejected expressions (such as -moz-calc(0 * 1em)) and the
rejection of previously-accepted ones (such as -moz-calc(0 + 1em)).
This commit is contained in:
L. David Baron 2010-12-30 12:59:33 -05:00
parent c64142dd70
commit 639cdb33d9
2 changed files with 37 additions and 1 deletions

View File

@ -7133,7 +7133,13 @@ CSSParserImpl::ParseCalcTerm(nsCSSValue& aValue, PRInt32& aVariantMask)
}
// ... or just a value
UngetToken();
if (!ParseVariant(aValue, aVariantMask, nsnull)) {
// Always pass VARIANT_NUMBER to ParseVariant so that unitless zero
// always gets picked up
if (!ParseVariant(aValue, aVariantMask | VARIANT_NUMBER, nsnull)) {
return PR_FALSE;
}
// ...and do the VARIANT_NUMBER check ourselves.
if (!(aVariantMask & VARIANT_NUMBER) && aValue.GetUnit() == eCSSUnit_Number) {
return PR_FALSE;
}
// If we did the value parsing, we need to adjust aVariantMask to

View File

@ -529,6 +529,22 @@ var gCSSProperties = {
"-moz-calc(2em / (4 / 3))",
"-moz-calc(4 * (2em / 3))",
// Valid cases with unitless zero (which is never
// a length).
"-moz-calc(0 * 2em)",
"-moz-calc(2em * 0)",
"-moz-calc(3em + 0 * 2em)",
"-moz-calc(3em + 2em * 0)",
"-moz-calc((0 + 2) * 2em)",
"-moz-calc((2 + 0) * 2em)",
// And test zero lengths while we're here.
"-moz-calc(2 * 0px)",
"-moz-calc(0 * 0px)",
"-moz-calc(2 * 0em)",
"-moz-calc(0 * 0em)",
"-moz-calc(0px * 0)",
"-moz-calc(0px * 2)",
],
invalid_values: [ "20", "-1px", "red", "50%",
/* invalid calc() values */
@ -560,6 +576,20 @@ var gCSSProperties = {
"-moz-calc((4 * 3) / 2em)",
"-moz-calc(4 * (3 / 2em))",
"-moz-calc(4 / (3 * 2em))",
// Tests for handling of unitless zero, which cannot
// be a length inside calc().
"-moz-calc(0)",
"-moz-calc(0 + 2em)",
"-moz-calc(2em + 0)",
"-moz-calc(0 * 2)",
"-moz-calc(2 * 0)",
"-moz-calc(1 * (2em + 0))",
"-moz-calc((2em + 0))",
"-moz-calc((2em + 0) * 1)",
"-moz-calc(1 * (0 + 2em))",
"-moz-calc((0 + 2em))",
"-moz-calc((0 + 2em) * 1)",
]
},
"-moz-column-rule-style": {