Bug 1355233 - quote unmatched open paren in function tokens correctly; r=gl
authorTom Tromey <tom@tromey.com>
Mon, 17 Apr 2017 08:00:58 -0600
changeset 353881 5323eee5a384afe38f3bd235a58e1713914ef169
parent 353880 00c020c70fe1b46f44a7922c79277261208a6e8d
child 353882 4a1023c9c098810251bc5bb21b5d2617982fa15d
push id31680
push userkwierso@gmail.com
push dateWed, 19 Apr 2017 23:57:00 +0000
treeherdermozilla-central@e9a5d4f62461 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1355233, 1321970
milestone55.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 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();