Reviewers: felix8a, Jasvir, Description: Allows -1E6 to 1E6 as valid z-indices. We reserve the values above and below that for our own use.
Please review this at http://codereview.appspot.com/5777044/ Affected files: M src/com/google/caja/lang/css/css21-defs.json M src/com/google/caja/parser/css/CssPropertySignature.java M tests/com/google/caja/plugin/CssRewriterTest.java M tests/com/google/caja/plugin/cssparser_test.js Index: tests/com/google/caja/plugin/cssparser_test.js =================================================================== --- tests/com/google/caja/plugin/cssparser_test.js (revision 4801) +++ tests/com/google/caja/plugin/cssparser_test.js (working copy) @@ -78,6 +78,7 @@ '@import "foo.css";', '@media print { th { font-weight: bolder } }', 'p.clazz q, s { color: blue; }', + 'DIV { z-index: -1; }', 'BODY { background: url(bg.png); font-family: Arial }', '* html a[href~="^https?://"]:after { content: "[ext]" }' ].join("\n"); @@ -96,6 +97,9 @@ 'startRuleset', [['p','.','clazz',' ','q',',',' ','s']], 'declaration', ['color',['blue']], 'endRuleset', + 'startRuleset', [['DIV']], + 'declaration', ['z-index',['-1']], + 'endRuleset', 'startRuleset', [['BODY']], 'declaration', ['background',['url("bg.png")']], 'declaration', ['font-family',['Arial']], // TODO: quote arial Index: tests/com/google/caja/plugin/CssRewriterTest.java =================================================================== --- tests/com/google/caja/plugin/CssRewriterTest.java (revision 4801) +++ tests/com/google/caja/plugin/CssRewriterTest.java (working copy) @@ -277,6 +277,35 @@ "div {\n margin: -5px 5px;\n z-index: 2\n}", false); } + public final void testZIndexRange() throws Exception { + runTest("div { z-index: 0 }", "div {\n z-index: 0\n}", false); + assertNoErrors(); + runTest( + "div { z-index: -1000000 }", + "div {\n z-index: -1000000\n}", + false); + assertNoErrors(); + runTest( + "div { z-index: 1000000 }", + "div {\n z-index: 1000000\n}", + false); + assertNoErrors(); + runTest( + "div { z-index: -1000001 }", + "div {\n z-index: -1000001\n}", + false); + assertMessage(PluginMessageType.CSS_VALUE_OUT_OF_RANGE, + MessageLevel.WARNING, + Name.css("z-index")); + runTest( + "div { z-index: 1000001 }", + "div {\n z-index: 1000001\n}", + false); + assertMessage(PluginMessageType.CSS_VALUE_OUT_OF_RANGE, + MessageLevel.WARNING, + Name.css("z-index")); + } + public final void testUserAgentHacks() throws Exception { runTest( "" Index: src/com/google/caja/lang/css/css21-defs.json =================================================================== --- src/com/google/caja/lang/css/css21-defs.json (revision 4801) +++ src/com/google/caja/lang/css/css21-defs.json (working copy) @@ -860,7 +860,7 @@ "dom2property": "wordSpacing" }, { "key": "z-index", - "signature": "auto | <integer> | inherit", + "signature": "auto | <integer:-1000000,1000000> | inherit", "default": "auto", "appliesTo": { "include": ["positioned"] }, "inherited": false, Index: src/com/google/caja/parser/css/CssPropertySignature.java =================================================================== --- src/com/google/caja/parser/css/CssPropertySignature.java (revision 4801) +++ src/com/google/caja/parser/css/CssPropertySignature.java (working copy) @@ -453,7 +453,7 @@ // whitespace Pattern.compile("^\\s+"), // a symbol, possibly with numeric bounds - Pattern.compile("^(<[a-zA-Z][\\w\\-]*(?:\\:\\d+,\\d*)?>)"), + Pattern.compile("^(<[a-zA-Z][\\w\\-]*(?:\\:-?\\d+,-?\\d*)?>)"), // a property reference Pattern.compile("^('[a-zA-Z][\\w\\-]*')"), // a literal keyword @@ -461,7 +461,7 @@ // a quoted literal Pattern.compile("^(\"[^\"]*\")"), // a number - Pattern.compile("^([0-9]+)\\b"), + Pattern.compile("^(-?[0-9]+)\\b"), // multi-character punctuation Pattern.compile("^(\\|\\|)"), // other single character tokens @@ -480,7 +480,9 @@ break; } } - if (!match) { throw new IllegalArgumentException(sig); } + if (!match) { + throw new IllegalArgumentException(sig); + } } return toks.listIterator(); }
