Skip to content

Commit

Permalink
Fix #401, space before attribute selector trimmed
Browse files Browse the repository at this point in the history
  • Loading branch information
Einar Lielmanis committed May 10, 2014
1 parent 496fa0d commit 3d611fc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion js/lib/beautify-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@
}
} else if (ch === ']') {
output.push(ch);
} else if (ch === '[' || ch === '=') { // no whitespace before or after
} else if (ch === '[') {
if (isAfterSpace) {
print.singleSpace();
}
output.push(ch);
} else if (ch === '=') { // no whitespace before or after
eatWhitespace();
output.push(ch);
} else {
Expand Down
3 changes: 3 additions & 0 deletions js/test/beautify-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,9 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
btc("a:not(\"foobar\\\";{}omg\"){\ncontent: 'example\\';{} text';\ncontent: \"example\\\";{} text\";}",
"a:not(\"foobar\\\";{}omg\") {\n content: 'example\\';{} text';\n content: \"example\\\";{} text\";\n}\n");

btc('html.js [data-custom="123"] {\n opacity: 1.00;\n}\n'); // may not eat the space before "["
btc('html.js *[data-custom="123"] {\n opacity: 1.00;\n}\n');

return sanitytest;
}

Expand Down
6 changes: 5 additions & 1 deletion python/cssbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ def beautify(self):
printer.singleSpace()
elif self.ch == ']':
printer.push(self.ch)
elif self.ch == '[' or self.ch == '=':
elif self.ch == '[':
if isAfterSpace:
printer.singleSpace()
printer.push(self.ch)
elif self.ch == '=':
# no whitespace before or after
self.eatWhitespace()
printer.push(self.ch)
Expand Down
4 changes: 4 additions & 0 deletions python/cssbeautifier/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def testBasics(self):
t("#bla, #foo{color:red}", "#bla,\n#foo {\n\tcolor: red\n}\n")
t("@media print {.tab{}}", "@media print {\n\t.tab {}\n}\n")

# may not eat the space before "["
t('html.js [data-custom="123"] {\n\topacity: 1.00;\n}\n');
t('html.js *[data-custom="123"] {\n\topacity: 1.00;\n}\n');


def testComments(self):
self.resetOptions()
Expand Down

0 comments on commit 3d611fc

Please sign in to comment.