Revision: 5588
Author: [email protected]
Date: Tue Sep 3 20:37:43 2013 UTC
Log: Make css-defs.js and the display property definition
vendor-prefix agnostic
https://codereview.appspot.com/12625043
I updated the "display" property which included several vendor-prefixed
values
(-moz-inline-stack and -moz-inline-box) so that they work with
sanitizecss.js
which now strips the prefix before checking the white-list, and I changed
CssPropertyPatterns to strip prefixes when generating white-lists.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=5588
Modified:
/trunk/src/com/google/caja/lang/css/CssPropertyPatterns.java
/trunk/src/com/google/caja/lang/css/css3-defs.json
/trunk/src/com/google/caja/lang/css/css3-whitelist.json
/trunk/tests/com/google/caja/plugin/CssValidatorTest.java
=======================================
--- /trunk/src/com/google/caja/lang/css/CssPropertyPatterns.java Thu Aug 22
21:49:41 2013 UTC
+++ /trunk/src/com/google/caja/lang/css/CssPropertyPatterns.java Tue Sep 3
20:37:43 2013 UTC
@@ -155,6 +155,38 @@
new Inspector(data).inspect();
return data;
}
+
+ private static final Set<String> KNOWN_VENDOR_PREFIXES =
Sets.immutableSet(
+ "apple",
+ "css",
+ "epub",
+ "khtml",
+ "moz",
+ "ms",
+ "mso",
+ "o",
+ "rim",
+ "wap",
+ "webkit",
+ "xv"
+ );
+
+ public static String withoutVendorPrefix(String cssIdentifier) {
+ if (cssIdentifier.startsWith("-")) {
+ int dash = cssIdentifier.indexOf('-', 1);
+ if (dash >= 0) {
+ String possiblePrefix = cssIdentifier.substring(1, dash);
+ if (KNOWN_VENDOR_PREFIXES.contains(possiblePrefix)) {
+ return cssIdentifier.substring(dash + 1);
+ }
+ }
+ }
+ return cssIdentifier;
+ }
+
+ public static boolean hasVendorPrefix(String cssIdentifier) {
+ return !cssIdentifier.equals(withoutVendorPrefix(cssIdentifier));
+ }
/**
* Walks a property signature to figure out what tokens can comprise its
@@ -213,7 +245,7 @@
// all positive matches are followed by token-breaking space.
// The pattern as a whole can then be matched against the value with
one
// space added at the end.
- data.literals.add(litValue);
+ data.literals.add(withoutVendorPrefix(litValue));
}
private void inspectRep(CssPropertySignature.RepeatedSignature sig) {
@@ -325,6 +357,7 @@
for (CssSchema.CssPropertyInfo prop : props) {
if (!schema.isPropertyAllowed(prop.name)) { continue; }
String key = prop.name.getCanonicalForm();
+ if (hasVendorPrefix(key)) { continue; }
CssPropertyData data = new CssPropertyData(key, prop.sig);
pp.new Inspector(data).inspect();
propData.add(Pair.pair(prop, data));
=======================================
--- /trunk/src/com/google/caja/lang/css/css3-defs.json Wed Aug 28 18:22:02
2013 UTC
+++ /trunk/src/com/google/caja/lang/css/css3-defs.json Tue Sep 3 20:37:43
2013 UTC
@@ -326,6 +326,14 @@
"inherited": false,
"mediaGroups": ["visual"] },
+ { "key": "box",
+ "signature": "normal | none | contents",
+ "default": "normal",
+ "appliesTo": "*",
+ "inherited": false,
+ "mediaGroups": "*",
+ "source": "http://dev.w3.org/csswg/css-display-3/#box" },
+
{ "key": "box-shadow",
"signature": "none | [ <shadow>, ]* <shadow>",
"default": "none",
@@ -439,11 +447,46 @@
"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 | -moz-inline-box | -moz-inline-stack",
+ "signature": "inline | block | list-item | run-in | inline-list-item
| inline-block | table | inline-table | table-cell | table-caption | flex |
inline-flex | grid | inline-grid | [ <display-inside> || <display-outside> |
| <display-extras> ] | inherit | inline-box | inline-stack",
"default": "inline",
"appliesTo": "*",
"inherited": false,
- "mediaGroups": "*" },
+ "mediaGroups": "*",
+ "source": "http://dev.w3.org/csswg/css-display-3/#the-display",
+ "comment": "inline-box and inline-stack are not in the spec but are
recognized. The <display-box> in the spec is cruft according to email from
Tab Atkins" },
+
+ { "key": "display-inside",
+ "signature": "<display-inside>",
+ "default": "auto",
+ "appliesTo": "*",
+ "inherited": false,
+ "mediaGroups": "*",
+ "source": "http://dev.w3.org/csswg/css-display-3/#display-inside" },
+
+ { "key": "<display-inside>",
+ "signature": "auto | block | table | flex | grid" },
+
+ { "key": "display-outside",
+ "signature": "<display-outside>",
+ "default": "inline-level",
+ "appliesTo": "*",
+ "inherited": false,
+ "mediaGroups": "*",
+ "source": "http://dev.w3.org/csswg/css-display-3/#display-outside" },
+
+ { "key": "<display-outside>",
+ "signature": "block-level | inline-level | none | table-row-group |
table-header-group | table-footer-group | table-row | table-cell |
table-column-group | table-column | table-caption" },
+
+ { "key": "display-extras",
+ "signature": "<display-extras>",
+ "default": "inline-level",
+ "appliesTo": "*",
+ "inherited": false,
+ "mediaGroups": "*",
+ "source": "http://dev.w3.org/csswg/css-display-3/#display-extras" },
+
+ { "key": "<display-extras>",
+ "signature": "none | [ list-item ]" },
{ "key": "elevation",
"signature": "<angle> | below | level | above | higher | lower",
=======================================
--- /trunk/src/com/google/caja/lang/css/css3-whitelist.json Mon Aug 19
22:38:58 2013 UTC
+++ /trunk/src/com/google/caja/lang/css/css3-whitelist.json Tue Sep 3
20:37:43 2013 UTC
@@ -51,6 +51,7 @@
"border-top-width",
"border-width",
"bottom",
+ "box",
"box-shadow",
"box-sizing",
"caption-side",
@@ -64,6 +65,9 @@
"cursor",
"direction",
"display",
+ "display-extras",
+ "display-inside",
+ "display-outside",
"elevation",
"empty-cells",
"filter",
=======================================
--- /trunk/tests/com/google/caja/plugin/CssValidatorTest.java Wed Aug 28
18:22:02 2013 UTC
+++ /trunk/tests/com/google/caja/plugin/CssValidatorTest.java Tue Sep 3
20:37:43 2013 UTC
@@ -54,7 +54,7 @@
+ " EmptyDeclaration\n",
// TODO(felix8a): error message is confusing
"WARNING: css property display has bad value:"
- + " ==>inherit<== inherit");
+ + " inherit ==><== inherit");
}
public final void testGlobalName() throws Exception {
--
---
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.