Bug 1323713 - fix prettify CSS error when encountering extra closing brace;r=tromey
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 10 Jan 2017 22:19:47 +0100
changeset 328842 d76704f625c7ba40dc8441b1f4bf90ec5fce920d
parent 328841 d1d89a3a187aa24845db5886cf0bc89747e2db5b
child 328843 5d1623b6bcca7e75035927970371b6db1485e0d5
push id31190
push usercbook@mozilla.com
push dateWed, 11 Jan 2017 15:21:29 +0000
treeherdermozilla-central@5493551203ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1323713
milestone53.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 1323713 - fix prettify CSS error when encountering extra closing brace;r=tromey MozReview-Commit-ID: 5TAxEP5561K
devtools/shared/inspector/css-logic.js
devtools/shared/tests/unit/test_prettifyCSS.js
--- a/devtools/shared/inspector/css-logic.js
+++ b/devtools/shared/inspector/css-logic.js
@@ -279,17 +279,21 @@ function prettifyCSS(text, ruleCount) {
         result = result + indent + text.substring(startIndex, endIndex);
         if (isCloseBrace) {
           result += prettifyCSS.LINE_SEPARATOR;
         }
       }
     }
 
     if (isCloseBrace) {
-      indent = TAB_CHARS.repeat(--indentLevel);
+      // Even if the stylesheet contains extra closing braces, the indent level should
+      // remain > 0.
+      indentLevel = Math.max(0, indentLevel - 1);
+
+      indent = TAB_CHARS.repeat(indentLevel);
       result = result + indent + "}";
     }
 
     if (!token) {
       break;
     }
 
     if (token.tokenType === "symbol" && token.text === "{") {
--- a/devtools/shared/tests/unit/test_prettifyCSS.js
+++ b/devtools/shared/tests/unit/test_prettifyCSS.js
@@ -44,16 +44,29 @@ const TESTS = [
   { name: "leading whitespace",
     input: "\n    div{color: red;}",
     expected: [
       "div {",
       "\tcolor: red;",
       "}"
     ]
   },
+
+  { name: "CSS with extra closing brace",
+    input: "body{margin:0}} div{color:red}",
+    expected: [
+      "body {",
+      "\tmargin:0",
+      "}",
+      "}",
+      "div {",
+      "\tcolor:red",
+      "}",
+    ]
+  },
 ];
 
 function run_test() {
   // Note that prettifyCSS.LINE_SEPARATOR is computed lazily, so we
   // ensure it is set.
   prettifyCSS("");
 
   for (let test of TESTS) {