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
--- 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();