Bug 1154356 - Escape variable name in Declaration::AppendVariableAndValueToString. r=heycam
☠☠ backed out by caf25344f73e ☠ ☠
authorTom Tromey <tromey@mozilla.com>
Fri, 24 Apr 2015 13:15:00 -0400
changeset 241211 ecc645744a1134ce0e302611c8320a73f622a00a
parent 241210 1d7c532f2a627f129d329dca47917b2c18032556
child 241212 41a196273ff9deeb3c64dd7294461f2d647f535f
push id59046
push userryanvm@gmail.com
push dateMon, 27 Apr 2015 14:18:52 +0000
treeherdermozilla-inbound@ecc645744a11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1154356
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1154356 - Escape variable name in Declaration::AppendVariableAndValueToString. r=heycam
layout/style/Declaration.cpp
layout/style/test/test_variables.html
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -1166,18 +1166,20 @@ Declaration::AppendPropertyAndValueToStr
   }
   aResult.AppendLiteral("; ");
 }
 
 void
 Declaration::AppendVariableAndValueToString(const nsAString& aName,
                                             nsAString& aResult) const
 {
-  aResult.AppendLiteral("--");
-  aResult.Append(aName);
+  nsAutoString localName;
+  localName.AppendLiteral("--");
+  localName.Append(aName);
+  nsStyleUtil::AppendEscapedCSSIdent(localName, aResult);
   CSSVariableDeclarations::Type type;
   nsString value;
   bool important;
 
   if (mImportantVariables && mImportantVariables->Get(aName, type, value)) {
     important = true;
   } else {
     MOZ_ASSERT(mVariables);
--- a/layout/style/test/test_variables.html
+++ b/layout/style/test/test_variables.html
@@ -21,16 +21,19 @@
 <style id="test5">
 </style>
 
 <div id="t5"></div>
 
 <style id="test6">
 </style>
 
+<style id="test7">
+</style>
+
 <script>
 var tests = [
   function() {
     // https://bugzilla.mozilla.org/show_bug.cgi?id=773296#c121
     var test1 = document.getElementById("test1");
     test1.textContent = "p { --a:123!important; }";
     var declaration = test1.sheet.cssRules[0].style;
     declaration.cssText;
@@ -86,16 +89,25 @@ var tests = [
   function() {
     // https://bugzilla.mozilla.org/show_bug.cgi?id=969756
     var test6 = document.getElementById("test6");
     test6.textContent = "p { font: var(--var6) hangul mongolian; font-size-adjust: none; }";
     var declaration = test6.sheet.cssRules[0].style;
     test6.style.color = "white";
     is(declaration.getPropertyValue("-x-system-font"), " var(--var6) hangul mongolian");
   },
+
+  function() {
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=1154356
+    var test7 = document.getElementById("test7");
+    test7.textContent = "p { --weird\\;name: green; }";
+    is(test7.sheet.cssRules[0].style.cssText, "--weird\\;name:  green;");
+    test7.textContent = "p { --0: green; }";
+    is(test7.sheet.cssRules[0].style.cssText, "--0:  green;");
+  },
 ];
 
 function prepareTest() {
   // Load an external style sheet for test 4.
   var e = document.createElement("link");
   e.addEventListener("load", runTest);
   e.setAttribute("rel", "stylesheet");
   e.setAttribute("href", "support/external-variable-url.css");