Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop reformatting valid css \! into invalid \ ! #1656

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/css/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Beautifier.prototype.beautify = function() {
if (whitespaceChar.test(this._ch)) {
this._ch = '';
}
} else if (this._ch === '!') { // !important
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
this.print_string(' ');
this.print_string(this._ch);
} else {
Expand Down
4 changes: 4 additions & 0 deletions js/test/generated/beautify-css-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10672,6 +10672,10 @@ function run_css_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_bea
'a {\n' +
'\tcolor: blue !important;\n' +
'}');
t(
'.blue\\! {\n' +
'\tcolor: blue !important;\n' +
'}');


//============================================================
Expand Down
3 changes: 2 additions & 1 deletion python/cssbeautifier/css/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def beautify(self):
self.print_string('=')
if bool(whitespaceChar.search(self._ch)):
self._ch = ''
elif self._ch == '!': # !important
elif self._ch == '!' and not (self._input.lookBack('\\')):
# !important
self.print_string(' ')
self.print_string(self._ch)
else:
Expand Down
4 changes: 4 additions & 0 deletions python/cssbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10550,6 +10550,10 @@ def testGenerated(self):
'a {\n' +
'\tcolor: blue !important;\n' +
'}')
t(
'.blue\\! {\n' +
'\tcolor: blue !important;\n' +
'}')


#============================================================
Expand Down
2 changes: 2 additions & 0 deletions test/data/css/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ exports.test_data = {
output: 'a {\n\tcolor: blue !important;\n}'
}, {
unchanged: 'a {\n\tcolor: blue !important;\n}'
}, {
unchanged: '.blue\\\\! {\n\tcolor: blue !important;\n}'
}]
}, {
name: "indent_empty_lines true",
Expand Down