Revision: 5584
Author:   [email protected]
Date:     Wed Aug 28 18:22:02 2013 UTC
Log:      accept "inherit" for all css properties
https://codereview.appspot.com/13146044

The css standards are generally written to omit "inherit" from
property specifications, but the standards also have a paragraph
near the beginning that says "inherit" is valid for all properties
despite being omitted from the property specifications.

Our css whitelisting inconsistently allows "inherit" for some
properties, not all.

This change makes "inherit" always an acceptable value.

There are a few quirks:

- The client-side css sanitizer is looser than the server-side one,
  because the client-side sanitizer only checks tokens, not full
  expressions. This applies to all types of css values, but for
  "inherit" in particular, the client-side sanitizer accepts
    p { color: inherit inherit; }
  which the server-side sanitizer rejects.

- The server-side sanitizer had some tests that accepted things like
    p { font: inherit "foo"; }
  which is not actually legal; browsers reject that rule. I deleted
  the tests.

- The rule for "content" explicitly disallowed "inherit", from a
  concern that it could bring in values defined in a parent element.
  This is unlikely to be a problem, because "content" is almost
  always set on ::before and ::after pseudo-elements, which
  cannot have children.

R=kpreid2


http://code.google.com/p/google-caja/source/detail?r=5584

Modified:
 /trunk/src/com/google/caja/lang/css/CssSchema.java
 /trunk/src/com/google/caja/lang/css/css3-defs.json
 /trunk/src/com/google/caja/plugin/CssValidator.java
 /trunk/src/com/google/caja/plugin/sanitizecss.js
 /trunk/tests/com/google/caja/lang/css/CssPropertyPatternsTest.java
 /trunk/tests/com/google/caja/lang/css/CssSchemaTest.java
 /trunk/tests/com/google/caja/plugin/CssValidatorTest.java
 /trunk/tests/com/google/caja/plugin/sanitizecss_test.js

=======================================
--- /trunk/src/com/google/caja/lang/css/CssSchema.java Thu Aug 22 21:49:41 2013 UTC +++ /trunk/src/com/google/caja/lang/css/CssSchema.java Wed Aug 28 18:22:02 2013 UTC
@@ -334,6 +334,7 @@
       }, null);
     }
     keywords.add(Name.css("initial"));
+    keywords.add(Name.css("inherit"));
   }

   private static class RegexpCriterion implements Criterion<String> {
=======================================
--- /trunk/src/com/google/caja/lang/css/css3-defs.json Thu Aug 22 21:49:41 2013 UTC +++ /trunk/src/com/google/caja/lang/css/css3-defs.json Wed Aug 28 18:22:02 2013 UTC
@@ -89,7 +89,7 @@
     },

     { "key": "azimuth",
- "signature": "<angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards | inherit", + "signature": "<angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards",
       "default": "center",
       "appliesTo": "*",
       "inherited": true,
@@ -125,7 +125,7 @@
     },

     { "key": "background-color",
-      "signature": "<color> | transparent | inherit",
+      "signature": "<color> | transparent",
       "default": "transparent",
       "appliesTo": "*",
       "inherited": false,
@@ -172,7 +172,7 @@
"source": "http://dev.w3.org/csswg/css-backgrounds/#background-size"; },

     { "key": "border",
- "signature": "[ <border-width> || <border-style> || [<color> | transparent] ] | inherit", + "signature": "[ <border-width> || <border-style> || [<color> | transparent] ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
@@ -208,14 +208,14 @@
       "as": "border-top-width" },

     { "key": "border-collapse",
-      "signature": "collapse | separate | inherit",
+      "signature": "collapse | separate",
       "default": "separate",
       "appliesTo": { "include": ["table", "inline-table"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "border-color",
-      "signature": "[ <color> | transparent ]{1,4} | inherit",
+      "signature": "[ <color> | transparent ]{1,4}",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
@@ -254,28 +254,28 @@
       "as": "border-top-width" },

     { "key": "border-spacing",
-      "signature": "<length> <length>? | inherit",
+      "signature": "<length> <length>?",
       "default": "0",
       "appliesTo": { "include": ["table", "inline-table"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "border-style",
-      "signature": "<border-style>{1,4} | inherit",
+      "signature": "<border-style>{1,4}",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "border-top",
- "signature": "[ <border-width> || <border-style> | | 'border-top-color' ] | inherit", + "signature": "[ <border-width> || <border-style> | | 'border-top-color' ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "border-top-color",
-      "signature": "<color> | transparent | inherit",
+      "signature": "<color> | transparent",
"default": null, "default-comment": "the value of the 'color' property",
       "appliesTo": "*",
       "inherited": false,
@@ -299,28 +299,28 @@
       "comment": "Note the nonstandard name. Used in Firefox 1.0 - 12.0" },

     { "key": "border-top-style",
-      "signature": "<border-style> | inherit",
+      "signature": "<border-style>",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "border-top-width",
-      "signature": "<border-width> | inherit",
+      "signature": "<border-width>",
       "default": "medium",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "border-width",
-      "signature": "<border-width>{1,4} | inherit",
+      "signature": "<border-width>{1,4}",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "bottom",
-      "signature": "<length> | <percentage> | auto | inherit",
+      "signature": "<length> | <percentage> | auto",
       "default": "auto",
       "appliesTo": { "include": ["positioned"] },
       "inherited": false,
@@ -335,7 +335,7 @@
       "source": "http://dev.w3.org/csswg/css3-background/#box-shadow"; },

     { "key": "box-sizing",
-      "signature": "content-box | padding-box | border-box | inherit",
+      "signature": "content-box | padding-box | border-box",
       "default": "content-box",
       "appliesTo": "*",
       "inherited": false,
@@ -343,28 +343,28 @@
       "source": "http://dev.w3.org/csswg/css-ui/#box-sizing"; },

     { "key": "caption-side",
-      "signature": "top | bottom | inherit",
+      "signature": "top | bottom",
       "default": "top",
       "appliesTo": { "include": ["table-caption"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "clear",
-      "signature": "none | left | right | both | inherit",
+      "signature": "none | left | right | both",
       "default": "none",
       "appliesTo": { "include": ["block"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "clip",
-      "signature": "<shape> | auto | inherit",
+      "signature": "<shape> | auto",
       "default": "auto",
       "appliesTo": { "include": ["absolutely-positioned"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "color",
-      "signature": "<color> | inherit",
+      "signature": "<color>",
       "default": null, "default-comment": "depends on user agent",
       "appliesTo": "*",
       "inherited": true,
@@ -373,54 +373,58 @@
     { "key": "content",
       "signature": "normal | none | <string> +",
       "default": " \"\" ",
+      "inherited": false,
       "description": [
         "Allow per CSS spec with some exceptions",
         "Reject <counter> because it exposes global page state",
"Reject attr(<identifier>) because it circumvents Domado attribute value virtualizations", - "Reject inherit because of possible strange semantics with stuff outside the Domado container", "Reject <uri> because, if we accept it, our CSS sanitizers assume any string is a URI", "Reject no-open-quote and no-close-quote because they expose a global counter", - "Reject open-quote and close-quote because we cannot test for them yet" + "Reject open-quote and close-quote because we cannot test for them yet", + "Note that 'inherit' is implicitly allowed, which might be a problem", + "if some trusted element has 'content' and admits untrusted children",
+        "but that's unlikely because 'content' is almost always used on",
+        "::before and ::after pseudo-elements, which cannot have children"
       ]
     },

     { "key": "counter-increment",
-      "signature": "[ <identifier> <integer>? ]+ | none | inherit",
+      "signature": "[ <identifier> <integer>? ]+ | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": "*" },

     { "key": "counter-reset",
-      "signature": "[ <identifier> <integer>? ]+ | none | inherit",
+      "signature": "[ <identifier> <integer>? ]+ | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": "*" },

     { "key": "cue",
-      "signature": "[ 'cue-before' || 'cue-after' ] | inherit",
+      "signature": "[ 'cue-before' || 'cue-after' ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "cue-after",
-      "signature": "<uri> | none | inherit",
+      "signature": "<uri> | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "cue-before",
-      "signature": "<uri> | none | inherit",
+      "signature": "<uri> | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "cursor",
- "signature": "[ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | text | wait | help | progress | all-scroll | col-resize | hand | no-drop | not-allowed | row-resize | vertical-text ] ] | inherit", + "signature": "[ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | text | wait | help | progress | all-scroll | col-resize | hand | no-drop | not-allowed | row-resize | vertical-text ] ]",
       "default": "auto",
       "appliesTo": "*",
       "inherited": true,
@@ -428,28 +432,28 @@
       "source": "http://www.quirksmode.org/css/cursor.html"; },

     { "key": "direction",
-      "signature": "ltr | rtl | inherit",
+      "signature": "ltr | rtl",
       "default": "ltr",
       "appliesTo": "*", "appliesTo-comment": "but see prose",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "display",
- "signature": "inline | block | list-item | run-in | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit | -moz-inline-box | -moz-inline-stack", + "signature": "inline | block | list-item | run-in | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | -moz-inline-box | -moz-inline-stack",
       "default": "inline",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": "*" },

     { "key": "elevation",
- "signature": "<angle> | below | level | above | higher | lower | inherit",
+      "signature": "<angle> | below | level | above | higher | lower",
       "default": "level",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "empty-cells",
-      "signature": "show | hide | inherit",
+      "signature": "show | hide",
       "default": "show",
       "appliesTo": { "include": ["table-cell"] },
       "inherited": true,
@@ -471,7 +475,7 @@
     },

     { "key": "float",
-      "signature": "left | right | none | inherit",
+      "signature": "left | right | none",
       "default": "none",
       "appliesTo": "*",
       "appliesTo-comment": "but see 9.7",
@@ -479,21 +483,21 @@
       "mediaGroups": ["visual"] },

     { "key": "font",
- "signature": "[ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit", + "signature": "[ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "font-family",
- "signature": "[[ <family-name> | <generic-family> ] [, [ <family-name> | <generic-family> ]]* ] | inherit", + "signature": "[[ <family-name> | <generic-family> ] [, [ <family-name> | <generic-family> ]]* ]",
       "default": null, "default-comment": "depends on user agent",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "font-size",
- "signature": "<absolute-size> | <relative-size> | <length:0,> | <percentage:0,> | inherit", + "signature": "<absolute-size> | <relative-size> | <length:0,> | <percentage:0,>",
       "default": "medium",
       "appliesTo": "*",
       "inherited": true,
@@ -509,28 +513,28 @@
     },

     { "key": "font-style",
-      "signature": "normal | italic | oblique | inherit",
+      "signature": "normal | italic | oblique",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "font-variant",
-      "signature": "normal | small-caps | inherit",
+      "signature": "normal | small-caps",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "font-weight",
- "signature": "normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit", + "signature": "normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "height",
-      "signature": "<length> | <percentage> | auto | inherit",
+      "signature": "<length> | <percentage> | auto",
       "default": "auto",
       "appliesTo": "*",
       "appliesTo-comment":
@@ -539,56 +543,56 @@
       "mediaGroups": ["visual"] },

     { "key": "left",
-      "signature": "<length> | <percentage> | auto | inherit",
+      "signature": "<length> | <percentage> | auto",
       "default": "auto",
       "appliesTo": { "include": ["positioned"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "letter-spacing",
-      "signature": "normal | <length> | inherit",
+      "signature": "normal | <length>",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "line-height",
- "signature": "normal | <number:0,> | <length:0,> | <percentage:0,> | inherit",
+      "signature": "normal | <number:0,> | <length:0,> | <percentage:0,>",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "list-style",
- "signature": "[ 'list-style-type' || 'list-style-position' | | 'list-style-image' ] | inherit", + "signature": "[ 'list-style-type' || 'list-style-position' | | 'list-style-image' ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": { "include": ["display: list-item"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "list-style-image",
-      "signature": "<image> | none | inherit",
+      "signature": "<image> | none",
       "default": "none",
       "appliesTo": { "include": ["display: list-item"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "list-style-position",
-      "signature": "inside | outside | inherit",
+      "signature": "inside | outside",
       "default": "outside",
       "appliesTo": { "include": ["display: list-item"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "list-style-type",
- "signature": "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none | inherit", + "signature": "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none",
       "default": "disc",
       "appliesTo": { "include": ["display: list-item"] },
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "margin",
-      "signature": "<margin-width>{1,4} | inherit",
+      "signature": "<margin-width>{1,4}",
       "default": null, "default-comment": "see individual properties",
       "appliesTo":
{ "exclude": [ "tr", "tbody", "thead", "tfoot", "col", "colgroup", "td", "th"] },
@@ -600,7 +604,7 @@
     { "key": "margin-left", "as": "margin-right" },

     { "key": "margin-right",
-      "signature": "<margin-width> | inherit",
+      "signature": "<margin-width>",
       "default": "0",
       "appliesTo":
{ "exclude": [ "tr", "tbody", "thead", "tfoot", "col", "colgroup", "td", "th"] },
@@ -610,7 +614,7 @@
       "mediaGroups": ["visual"] },

     { "key": "margin-top",
-      "signature": "<margin-width> | inherit",
+      "signature": "<margin-width>",
       "default": "0",
       "appliesTo":
{ "exclude": [ "tr", "tbody", "thead", "tfoot", "col", "colgroup", "td", "th"] },
@@ -618,7 +622,7 @@
       "mediaGroups": ["visual"] },

     { "key": "max-height",
-      "signature": "<length:0,> | <percentage:0,> | none | inherit | auto",
+      "signature": "<length:0,> | <percentage:0,> | none | auto",
       "default": "none",
       "appliesTo": { "exclude": [ "col", "colgroup"] },
"appliesTo-comment": "All elements but non-replaced inline elements, table columns, and column groups",
@@ -627,7 +631,7 @@
       "description": "the value 'auto' is a quirk specific to IE7" },

     { "key": "max-width",
-      "signature": "<length:0,> | <percentage:0,> | none | inherit | auto",
+      "signature": "<length:0,> | <percentage:0,> | none | auto",
       "default": "none",
"appliesTo": { "exclude": [ "tbody", "thead", "tfoot", "row", "tr"] },
       "inherited": false,
@@ -635,7 +639,7 @@
       "description": "the value 'auto' is a quirk specific to IE7" },

     { "key": "min-height",
-      "signature": "<length:0,> | <percentage:0,> | inherit | auto",
+      "signature": "<length:0,> | <percentage:0,> | auto",
       "default": "0",
"appliesTo": { "include": ["inline", "table-column", "column-group"] },
       "inherited": false,
@@ -643,7 +647,7 @@
       "description": "the value 'auto' is a quirk specific to IE7" },

     { "key": "min-width",
-      "signature": "<length:0,> | <percentage:0,> | inherit | auto",
+      "signature": "<length:0,> | <percentage:0,> | auto",
       "default": "0",
       "appliesTo": { "include": ["inline", "table-row", "row-group"] },
       "inherited": false,
@@ -651,7 +655,7 @@
       "description": "the value 'auto' is a quirk specific to IE7" },

     { "key": "opacity",
-      "signature": "<alphavalue> | inherit",
+      "signature": "<alphavalue>",
       "default": "1",
       "appliesTo": "*",
       "inherited": false,
@@ -664,49 +668,49 @@
{ "key": "<alpha>", "signature": "<integer:0,255>|<number:0,1>| <percentage:0,100>" },

     { "key": "orphans",
-      "signature": "<integer:0,> | inherit",
+      "signature": "<integer:0,>",
       "default": "2",
       "appliesTo": { "include": ["block"] },
       "inherited": true,
       "mediaGroups": ["visual", "paged"] },

     { "key": "outline",
- "signature": "[ 'outline-color' || 'outline-style' | | 'outline-width' ] | inherit", + "signature": "[ 'outline-color' || 'outline-style' | | 'outline-width' ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual", "interactive"] },

     { "key": "outline-color",
-      "signature": "<color> | invert | inherit",
+      "signature": "<color> | invert",
       "default": "invert",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual", "interactive"] },

     { "key": "outline-style",
-      "signature": "<border-style> | inherit",
+      "signature": "<border-style>",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual", "interactive"] },

     { "key": "outline-width",
-      "signature": "<border-width> | inherit",
+      "signature": "<border-width>",
       "default": "medium",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual", "interactive"] },

     { "key": "overflow",
-      "signature": "visible | hidden | scroll | auto | inherit",
+      "signature": "visible | hidden | scroll | auto",
       "default": "visible",
       "appliesTo": { "include": ["block", "table cell", "inline block"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "overflow-wrap",
-      "signature": "normal | break-word | inherit",
+      "signature": "normal | break-word",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
@@ -724,7 +728,7 @@
     { "key": "overflow-y", "as": "overflow-x" },

     { "key": "padding",
-      "signature": "<padding-width>{1,4} | inherit",
+      "signature": "<padding-width>{1,4}",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": { "exclude": [
             "table-row-group", "table-header-group", "table-footer-group",
@@ -739,7 +743,7 @@
     { "key": "padding-right", "as": "padding-top" },

     { "key": "padding-top",
-      "signature": "<padding-width> | inherit",
+      "signature": "<padding-width>",
       "default": "0",
       "appliesTo": { "exclude": [
             "table-row-group", "table-header-group", "table-footer-group",
@@ -748,42 +752,42 @@
       "mediaGroups": ["visual"] },

     { "key": "page-break-after",
-      "signature": "auto | always | avoid | left | right | inherit",
+      "signature": "auto | always | avoid | left | right",
       "default": "auto",
       "appliesTo": { "include": ["block"] },
       "inherited": false,
       "mediaGroups": ["visual", "paged"] },

     { "key": "page-break-before",
-      "signature": "auto | always | avoid | left | right | inherit",
+      "signature": "auto | always | avoid | left | right",
       "default": "auto",
       "appliesTo": { "include": ["block"] },
       "inherited": false,
       "mediaGroups": ["visual", "paged"] },

     { "key": "page-break-inside",
-      "signature": "avoid | auto | inherit",
+      "signature": "avoid | auto",
       "default": "auto",
       "appliesTo": { "include": ["block"] },
       "inherited": true,
       "mediaGroups": ["visual", "paged"] },

     { "key": "pause",
-      "signature": "[ [<time> | <percentage>]{1,2} ] | inherit",
+      "signature": "[ [<time> | <percentage>]{1,2} ]",
       "default": null, "default-comment": "see individual properties",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "pause-after",
-      "signature": "<time> | <percentage> | inherit",
+      "signature": "<time> | <percentage>",
       "default": "0",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "pause-before",
-      "signature": "<time> | <percentage> | inherit",
+      "signature": "<time> | <percentage>",
       "default": "0",
       "appliesTo": "*",
       "inherited": false,
@@ -808,28 +812,28 @@
     },

     { "key": "pitch",
- "signature": "<frequency> | x-low | low | medium | high | x-high | inherit",
+      "signature": "<frequency> | x-low | low | medium | high | x-high",
       "default": "medium",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "pitch-range",
-      "signature": "<number> | inherit",
+      "signature": "<number>",
       "default": "50",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "play-during",
-      "signature": "<uri> [ mix || repeat ]? | auto | none | inherit",
+      "signature": "<uri> [ mix || repeat ]? | auto | none",
       "default": "auto",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["aural"] },

     { "key": "position",
-      "signature": "static | relative | absolute | inherit",
+      "signature": "static | relative | absolute",
       "signature-comment": "'fixed' is not allowed",
       "default": "static",
       "appliesTo": "*",
@@ -837,35 +841,35 @@
       "mediaGroups": ["visual"] },

     { "key": "quotes",
-      "signature": "[<string> <string>]+ | none | inherit",
+      "signature": "[<string> <string>]+ | none",
       "default": null, "default-comment": "depends on user agent",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "richness",
-      "signature": "<number> | inherit",
+      "signature": "<number>",
       "default": "50",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "right",
-      "signature": "<length> | <percentage> | auto | inherit",
+      "signature": "<length> | <percentage> | auto",
       "default": "auto",
       "appliesTo": { "include": ["positioned"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "speak",
-      "signature": "normal | none | spell-out | inherit",
+      "signature": "normal | none | spell-out",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "speak-header",
-      "signature": "once | always | inherit",
+      "signature": "once | always",
       "default": "once",
       "appliesTo": { "exclude": ["thead"] },
       "appliesTo-comment": "elements that have table header information",
@@ -873,42 +877,42 @@
       "mediaGroups": ["aural"] },

     { "key": "speak-numeral",
-      "signature": "digits | continuous | inherit",
+      "signature": "digits | continuous",
       "default": "continuous",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "speak-punctuation",
-      "signature": "code | none | inherit",
+      "signature": "code | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "speech-rate",
- "signature": "<number> | x-slow | slow | medium | fast | x-fast | faster | slower | inherit", + "signature": "<number> | x-slow | slow | medium | fast | x-fast | faster | slower",
       "default": "medium",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "stress",
-      "signature": "<number> | inherit",
+      "signature": "<number>",
       "default": "50",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "table-layout",
-      "signature": "auto | fixed | inherit",
+      "signature": "auto | fixed",
       "default": "auto",
       "appliesTo": { "include": ["table", "inline-table"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "text-align",
-      "signature": "left | right | center | justify | inherit",
+      "signature": "left | right | center | justify",
       "default":  null,
       "default-comment":
"'left' if 'direction' is 'ltr'; 'right' if 'direction' is 'rtl'",
@@ -917,14 +921,14 @@
       "mediaGroups": ["visual"] },

     { "key": "text-decoration",
- "signature": "none | [ underline || overline || line-through || blink ] | inherit", + "signature": "none | [ underline || overline || line-through || blink ]",
       "default": "none",
       "appliesTo": "*",
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "text-indent",
-      "signature": "<length> | <percentage> | inherit",
+      "signature": "<length> | <percentage>",
       "default": "0",
       "appliesTo": { "include": ["block", "table cell", "inline block"] },
       "inherited": true,
@@ -949,7 +953,7 @@
"signature": "[<color> <length>{2,4} inset?] | [ inset? <length>{2,4} <color>?]" },

     { "key": "text-transform",
-      "signature": "capitalize | uppercase | lowercase | none | inherit",
+      "signature": "capitalize | uppercase | lowercase | none",
       "default": "none",
       "appliesTo": "*",
       "inherited": true,
@@ -964,7 +968,7 @@
       "source": "http://dev.w3.org/csswg/css3-text/#text-wrap"; },

     { "key": "top",
-      "signature": "<length> | <percentage> | auto | inherit",
+      "signature": "<length> | <percentage> | auto",
       "default": "auto",
       "appliesTo": { "include": ["positioned"] },
       "inherited": false,
@@ -1042,7 +1046,7 @@
     },

     { "key": "unicode-bidi",
-      "signature": "normal | embed | bidi-override | inherit",
+      "signature": "normal | embed | bidi-override",
       "default": "normal",
       "appliesTo": "*",
       "appliesTo-comment": "but see prose",
@@ -1050,35 +1054,35 @@
       "mediaGroups": ["visual"] },

     { "key": "vertical-align",
- "signature": "baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> | <length> | inherit", + "signature": "baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> | <length>",
       "default": "baseline",
       "appliesTo": { "include": ["inline", "table-cell"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "visibility",
-      "signature": "visible | hidden | collapse | inherit",
+      "signature": "visible | hidden | collapse",
       "default": "visible",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["visual"] },

     { "key": "voice-family",
- "signature": "[[<specific-voice> | <generic-voice> ],]* [<specific-voice> | <generic-voice> ] | inherit", + "signature": "[[<specific-voice> | <generic-voice> ],]* [<specific-voice> | <generic-voice> ]",
       "default": null, "default-comment": "depends on user agent",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "volume",
- "signature": "<number:0,> | <percentage:0,> | silent | x-soft | soft | medium | loud | x-loud | inherit", + "signature": "<number:0,> | <percentage:0,> | silent | x-soft | soft | medium | loud | x-loud",
       "default": "medium",
       "appliesTo": "*",
       "inherited": true,
       "mediaGroups": ["aural"] },

     { "key": "white-space",
- "signature": "normal | pre | nowrap | pre-wrap | pre-line | inherit | -o-pre-wrap | -moz-pre-wrap | -pre-wrap",
+      "signature": "normal | pre | nowrap | pre-wrap | pre-line",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
@@ -1087,21 +1091,21 @@
     },

     { "key": "widows",
-      "signature": "<integer:0,> | inherit",
+      "signature": "<integer:0,>",
       "default": "2",
       "appliesTo": { "include": ["block"] },
       "inherited": true,
       "mediaGroups": ["visual", "paged"] },

     { "key": "width",
-      "signature": "<length:0,> | <percentage:0,> | auto | inherit",
+      "signature": "<length:0,> | <percentage:0,> | auto",
       "default": "auto",
       "appliesTo": { "exclude": ["inline", "table row", "row group"] },
       "inherited": false,
       "mediaGroups": ["visual"] },

     { "key": "word-break",
-      "signature": "normal | keep-all | break-all | inherit",
+      "signature": "normal | keep-all | break-all",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
@@ -1109,7 +1113,7 @@
       "source": "http://dev.w3.org/csswg/css-text/#word-break"; },

     { "key": "word-spacing",
-      "signature": "normal | <length> | inherit",
+      "signature": "normal | <length>",
       "default": "normal",
       "appliesTo": "*",
       "inherited": true,
@@ -1119,7 +1123,7 @@
       "as": "overflow-wrap" },

     { "key": "z-index",
-      "signature": "auto | <z-index:-9999999,9999999> | inherit",
+      "signature": "auto | <z-index:-9999999,9999999>",
       "default": "auto",
       "appliesTo": { "include": ["positioned"] },
       "inherited": false,
@@ -1143,12 +1147,12 @@
"signature": "xx-small|x-small|small|medium|large|x-large|xx-large" },

     { "key": "<attachment>",
-      "signature": "scroll | fixed | local | inherit",
+      "signature": "scroll | fixed | local",
       "source": "http://dev.w3.org/csswg/css-backgrounds/#ltattachmentgt";
     },

     { "key": "<bg-image>",
-      "signature": "<image> | none | inherit",
+      "signature": "<image> | none",
       "source": "http://dev.w3.org/csswg/css-backgrounds/#ltbg-imagegt";
     },

@@ -1158,7 +1162,7 @@
     },

     { "key": "<bg-position>",
- "signature": "[ [ [ <percentage> | <length> | left | center | right ] ] [ [ <percentage> | <length> | top | center | bottom ] ]? | [ [ center | [ left | right ] [ <percentage> | <length> ]? ] || [ center | [ top | bottom ] [ <percentage> | <length> ]? ] ] ] | inherit", + "signature": "[ [ [ <percentage> | <length> | left | center | right ] ] [ [ <percentage> | <length> | top | center | bottom ] ]? | [ [ center | [ left | right ] [ <percentage> | <length> ]? ] || [ center | [ top | bottom ] [ <percentage> | <length> ]? ] ] ]",
       "source": "http://dev.w3.org/csswg/css-backgrounds/#ltbg-positiongt";
     },

@@ -1176,7 +1180,7 @@
       "signature": "thin|medium|thick|<length>" },

     { "key": "<box>",
-      "signature": "border-box | padding-box | content-box | inherit",
+      "signature": "border-box | padding-box | content-box",
       "source": "http://dev.w3.org/csswg/css3-background/#background-clip";
     },

@@ -1314,7 +1318,7 @@
       "signature": "smaller|larger" },

     { "key": "<repeat-style>",
- "signature": "repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2} | inherit", + "signature": "repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}",
       "source": "http://dev.w3.org/csswg/css-backgrounds/#ltrepeat-stylegt";
     },

=======================================
--- /trunk/src/com/google/caja/plugin/CssValidator.java Mon Aug 19 22:29:55 2013 UTC +++ /trunk/src/com/google/caja/plugin/CssValidator.java Wed Aug 28 18:22:02 2013 UTC
@@ -225,6 +225,10 @@
       d.getAttributes().set(INVALID, Boolean.TRUE);
       return false;
     }
+    // inherit is always allowed
+    if (isInherit(d.getExpr())) {
+      return true;
+    }
     // Apply the signature
     if (!applySignature(pinfo.name, d.getExpr(), pinfo.sig)) {
       // Apply takes care of adding the error message
@@ -234,6 +238,19 @@

     return true;
   }
+
+  private boolean isInherit(CssTree.Expr expr) {
+    if (expr.getNTerms() == 1) {
+      CssTree.Term term = expr.getNthTerm(0);
+      if (term.getOperator() == null) {
+        CssTree.CssExprAtom atom = term.getExprAtom();
+        if (atom instanceof CssTree.IdentLiteral) {
+          return atom.getValue().equals("inherit");
+        }
+      }
+    }
+    return false;
+  }

   // See the similar function withoutVendorPrefix in sanitizecss.js
   private static String[] vendorPrefixes = {
=======================================
--- /trunk/src/com/google/caja/plugin/sanitizecss.js Wed Aug 28 18:04:38 2013 UTC +++ /trunk/src/com/google/caja/plugin/sanitizecss.js Wed Aug 28 18:22:02 2013 UTC
@@ -258,6 +258,10 @@
             : ''
           )

+          // inherit is always allowed.
+          : token === 'inherit'
+          ? token
+
           : (
             litGroup = propertySchema['cssLitGroup'],
             litMap = (litGroup
=======================================
--- /trunk/tests/com/google/caja/lang/css/CssPropertyPatternsTest.java Thu Aug 22 21:49:41 2013 UTC +++ /trunk/tests/com/google/caja/lang/css/CssPropertyPatternsTest.java Wed Aug 28 18:22:02 2013 UTC
@@ -117,7 +117,7 @@
     assertDigest(
         "'background-attachment'",
         "{\n"
-        + "  'lits': [ ',', 'fixed', 'inherit', 'local', 'scroll' ]\n"
+        + "  'lits': [ ',', 'fixed', 'local', 'scroll' ]\n"
         + "}");
   }

=======================================
--- /trunk/tests/com/google/caja/lang/css/CssSchemaTest.java Thu Aug 22 21:49:41 2013 UTC +++ /trunk/tests/com/google/caja/lang/css/CssSchemaTest.java Wed Aug 28 18:22:02 2013 UTC
@@ -69,6 +69,7 @@
     assertTrue(cssSchema.isKeyword(Name.css("auto")));
     assertTrue(cssSchema.isKeyword(Name.css("sans-serif")));
     assertTrue(cssSchema.isKeyword(Name.css("monospace")));
+    assertTrue(cssSchema.isKeyword(Name.css("DEFAULT")));
     assertTrue(cssSchema.isKeyword(Name.css("INHERIT")));
     assertFalse(cssSchema.isKeyword(Name.css("not-a-keyword")));
     assertFalse(cssSchema.isKeyword(Name.css("notakeyword")));
=======================================
--- /trunk/tests/com/google/caja/plugin/CssValidatorTest.java Mon Aug 19 22:29:55 2013 UTC +++ /trunk/tests/com/google/caja/plugin/CssValidatorTest.java Wed Aug 28 18:22:02 2013 UTC
@@ -39,6 +39,24 @@
  */
 public final class CssValidatorTest extends CajaTestCase {

+  public final void testInherit() throws Exception {
+    runTest("a { color: inherit; display: inherit inherit; }",
+        "StyleSheet\n"
+        + "  RuleSet\n"
+        + "    Selector\n"
+        + "      SimpleSelector\n"
+        + "        IdentLiteral : a\n"
+        + "    PropertyDeclaration\n"
+        + "      Property : color\n"
+        + "      Expr\n"
+        + "        Term\n"
+        + "          IdentLiteral : inherit\n"
+        + "    EmptyDeclaration\n",
+        // TODO(felix8a): error message is confusing
+        "WARNING: css property display has bad value:"
+        + " ==>inherit<==  inherit");
+  }
+
   public final void testGlobalName() throws Exception {
     runTest("a { animation-name: foo; }",
         "StyleSheet\n"
@@ -498,39 +516,6 @@
             "WARNING: css property font has bad value:"
             + " ==>italix<==  bolder 150% Arial");

-    // font-size also matches by previous terms
-    runTest("p, dl { font: inherit \"Arial\"; }",  // special
-            "StyleSheet\n"
-            + "  RuleSet\n"
-            + "    Selector\n"
-            + "      SimpleSelector\n"
-            + "        IdentLiteral : p\n"
-            + "    Selector\n"
-            + "      SimpleSelector\n"
-            + "        IdentLiteral : dl\n"
-            + "    PropertyDeclaration\n"
-            + "      Property : font\n"
-            + "      Expr\n"
-            + "        Term ; cssPropertyPartType=IDENT"
-                        + " ; cssPropertyPart=font-size\n"
-            + "          IdentLiteral : inherit\n"
-            + "        Operation : NONE\n"
-            + "        Term ; cssPropertyPartType=STRING"
-                        + " ; cssPropertyPart=font-family::family-name\n"
-            + "          StringLiteral : Arial\n"
-            + "    EmptyDeclaration");
-    runTest("p, dl { font: inherit; }",
-            "StyleSheet\n"
-            + "  RuleSet\n"
-            + "    Selector\n"
-            + "      SimpleSelector\n"
-            + "        IdentLiteral : p\n"
-            + "    Selector\n"
-            + "      SimpleSelector\n"
-            + "        IdentLiteral : dl\n"
-            + "    EmptyDeclaration",
-            "WARNING: css property font has bad value: inherit");
-
     // weight size family
     runTest("p, dl { font: 800 150% Arial; }",
             "StyleSheet\n"
@@ -711,34 +696,6 @@
             + "    EmptyDeclaration");
     warns("p, dl { font: normal 800 150%/-175% Arial; }");
     warns("p, dl { font: normal 800 150%/-17.5 Arial; }");
-
-    // make sure the first three inherits match different parts
-    runTest("p { font: inherit inherit inherit Arial; }",
-            "StyleSheet\n" +
-            "  RuleSet\n" +
-            "    Selector\n" +
-            "      SimpleSelector\n" +
-            "        IdentLiteral : p\n" +
-            "    PropertyDeclaration\n" +
-            "      Property : font\n" +
-            "      Expr\n" +
-            "        Term ; cssPropertyPartType=IDENT"
-                      + " ; cssPropertyPart=font-style\n" +
-            "          IdentLiteral : inherit\n" +
-            "        Operation : NONE\n" +
-            "        Term ; cssPropertyPartType=IDENT"
-                      + " ; cssPropertyPart=font-variant\n" +
-            "          IdentLiteral : inherit\n" +
-            "        Operation : NONE\n" +
-            "        Term ; cssPropertyPartType=IDENT"
-                      + " ; cssPropertyPart=font-size\n" +
-            "          IdentLiteral : inherit\n" +
-            "        Operation : NONE\n" +
-            "        Term ; cssPropertyPartType=LOOSE_WORD"
-                      + " ; cssPropertyPart=font-family::family-name"
-                                         + "::loose-quotable-words\n" +
-            "          IdentLiteral : Arial\n" +
-            "    EmptyDeclaration");
   }

   public final void testValidateUnquotedFamilyNames() throws Exception {
@@ -776,8 +733,7 @@
             + "    PropertyDeclaration\n"
             + "      Property : border\n"
             + "      Expr\n"
-            + "        Term ; cssPropertyPartType=IDENT"
-                        + " ; cssPropertyPart=border\n"
+            + "        Term\n"
             + "          IdentLiteral : inherit\n"
             + "    EmptyDeclaration");
     runTest("p { border: 2px }",
=======================================
--- /trunk/tests/com/google/caja/plugin/sanitizecss_test.js Wed Aug 21 04:26:59 2013 UTC +++ /trunk/tests/com/google/caja/plugin/sanitizecss_test.js Wed Aug 28 18:22:02 2013 UTC
@@ -45,6 +45,14 @@
   assertArrayEquals(input, golden, stylesheet);
 }

+jsunitRegister('testInherit', function testInherit() {
+  assertProperty('border', 'inherit', 'inherit');
+  // Note this is not a valid value, but it's harmless to allow it.
+  assertProperty('border', 'inherit inherit', 'inherit inherit');
+  jsunit.pass();
+});
+
+
 jsunitRegister('testFontFamily',
                function testFontFamily() {
   var tokens = ['Arial', ' ', 'Black', ',', 'monospace', ',',

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to