Revision: 5568
Author:   [email protected]
Date:     Wed Aug 21 04:26:59 2013 UTC
Log:      support vendor prefixes in css functions
https://codereview.appspot.com/12761044

linear-gradient() works but -webkit-linear-gradient() gets dropped.
this CL fixes that for the client-side css sanitizer.

fixing it in the server-side css sanitizer is a little harder
(because the leading '-' is parsed as a separate token),
so I've just marked a TODO and I'm deferring that for now.

R=mikesamuel


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

Modified:
 /trunk/src/com/google/caja/plugin/sanitizecss.js
 /trunk/tests/com/google/caja/plugin/CssRewriterTest.java
 /trunk/tests/com/google/caja/plugin/sanitizecss_test.js

=======================================
--- /trunk/src/com/google/caja/plugin/sanitizecss.js Tue Aug 13 00:53:18 2013 UTC +++ /trunk/src/com/google/caja/plugin/sanitizecss.js Wed Aug 21 04:26:59 2013 UTC
@@ -189,12 +189,13 @@
         // so allowing resumption at the next ';'.
         if (!parenDepth) {
           var fnToken = tokens[start].toLowerCase();
+          var bareFnToken = withoutVendorPrefix(fnToken);
           // Cut out the originals, so the caller can step by one token.
           var fnTokens = tokens.splice(start, end - start, '');
           var fns = propertySchema.cssFns;
           // Look for a function that matches the name.
           for (var i = 0, nFns = fns.length; i < nFns; ++i) {
-            if (fns[i].substring(0, fnToken.length) == fnToken) {
+            if (fns[i].substring(0, bareFnToken.length) == bareFnToken) {
               fnTokens[0] = fnTokens[fnTokens.length - 1] = '';
               // Recurse and sanitize the function parameters.
               sanitize(
=======================================
--- /trunk/tests/com/google/caja/plugin/CssRewriterTest.java Mon Aug 12 22:12:45 2013 UTC +++ /trunk/tests/com/google/caja/plugin/CssRewriterTest.java Wed Aug 21 04:26:59 2013 UTC
@@ -197,6 +197,14 @@
         pre + "background-image: linear-gradient(45deg, blue, red)\n}");
     assertNoErrors();

+    // TODO(felix8a): -vendor-func() doesn't work yet
+    /*
+    runTest(
+ "p { background-image: -webkit-linear-gradient(1deg, blue, red) }", + pre + "background-image: -webkit-linear-gradient(1deg, blue, red)\n}");
+    assertNoErrors();
+    */
+
// A gradient going from the bottom right to the top left starting blue and
     // finishing red
     runTest(
=======================================
--- /trunk/tests/com/google/caja/plugin/sanitizecss_test.js Wed Aug 7 00:29:48 2013 UTC +++ /trunk/tests/com/google/caja/plugin/sanitizecss_test.js Wed Aug 21 04:26:59 2013 UTC
@@ -327,6 +327,9 @@
   var source = 'linear-gradient(to bottom right, red, rgb(255,0,0))';
   var expect = 'linear-gradient(to bottom right , red , rgb(255 , 0 , 0))';
   assertProperty('background-image', source, expect);
+  source = '-webkit-' + source;
+  expect = '-webkit-' + expect;
+  assertProperty('background-image', source, expect);
   jsunit.pass();
 });

--

--- 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