Bug 1355233 - quote unmatched open paren in function tokens correctly; r?gl draft
authorTom Tromey <tom@tromey.com>
Mon, 17 Apr 2017 08:00:58 -0600
changeset 563615 5842698f058ddb7bf1bdcbbdac6b93c9c37f4d98
parent 562973 5270f76969889ceff66454cbf0c15d26ccd899a9
child 624532 82537f1437fdbfb6d6333edd3fa88229ac1446a6
push id54373
push userbmo:ttromey@mozilla.com
push dateMon, 17 Apr 2017 14:03:26 +0000
reviewersgl
bugs1355233, 1321970
milestone55.0a1
Bug 1355233 - quote unmatched open paren in function tokens correctly; r?gl When rewriting in the rule view, the rewriter quotes unmatched open parens to avoid some edits affecting the rest of the style sheet. This was bug 1321970. However, that change didn't correctly handle the case of a function token, where the paren in question appears at the end, not the start, of the token. MozReview-Commit-ID: GjA40M2KsvX
devtools/client/shared/test/unit/test_rewriteDeclarations.js
devtools/shared/css/parsing-utils.js
--- a/devtools/client/shared/test/unit/test_rewriteDeclarations.js
+++ b/devtools/client/shared/test/unit/test_rewriteDeclarations.js
@@ -520,16 +520,25 @@ const TEST_DATA = [
 
   {
     desc: "function regression test for bug 1321970",
     input: "",
     instruction: {type: "create", name: "p", value: "func(1,2)", priority: "",
                   index: 0, enabled: true},
     expected: "p: func(1,2);",
   },
+
+  {
+    desc: "function regression test for bug 1355233",
+    input: "",
+    instruction: {type: "create", name: "p", value: "func(", priority: "",
+                  index: 0, enabled: true},
+    expected: "p: func\\(;",
+    changed: {0: "func\\("}
+  },
 ];
 
 function rewriteDeclarations(inputString, instruction, defaultIndentation) {
   let rewriter = new RuleRewriter(isCssPropertyKnown, null, inputString);
   rewriter.defaultIndentation = defaultIndentation;
 
   switch (instruction.type) {
     case "rename":
--- a/devtools/shared/css/parsing-utils.js
+++ b/devtools/shared/css/parsing-utils.js
@@ -611,19 +611,22 @@ RuleRewriter.prototype = {
 
     let result = "";
     let previousOffset = 0;
     let parenStack = [];
     let anySanitized = false;
 
     // Push a closing paren on the stack.
     let pushParen = (token, closer) => {
-      result += text.substring(previousOffset, token.startOffset);
-      parenStack.push({closer, offset: result.length});
-      result += text.substring(token.startOffset, token.endOffset);
+      result = result + text.substring(previousOffset, token.startOffset) +
+        text.substring(token.startOffset, token.endOffset);
+      // We set the location of the paren in a funny way, to handle
+      // the case where we've seen a function token, where the paren
+      // appears at the end.
+      parenStack.push({closer, offset: result.length - 1});
       previousOffset = token.endOffset;
     };
 
     // Pop a closing paren from the stack.
     let popSomeParens = (closer) => {
       while (parenStack.length > 0) {
         let paren = parenStack.pop();