Bug 1323713 - fix prettify CSS error when encountering extra closing brace;r=tromey

MozReview-Commit-ID: 5TAxEP5561K

--HG--
extra : rebase_source : 41fdc014c018d2f2611e698a2292d15978e49df8
This commit is contained in:
Julian Descottes 2017-01-10 22:19:47 +01:00
parent 49420991ca
commit 4a16348236
2 changed files with 18 additions and 1 deletions

View File

@ -284,7 +284,11 @@ function prettifyCSS(text, ruleCount) {
}
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 + "}";
}

View File

@ -49,6 +49,19 @@ const TESTS = [
"}"
]
},
{ name: "CSS with extra closing brace",
input: "body{margin:0}} div{color:red}",
expected: [
"body {",
"\tmargin:0",
"}",
"}",
"div {",
"\tcolor:red",
"}",
]
},
];
function run_test() {