Skip to content

Commit

Permalink
Fix for multiple consequent spaces present in CSS selectors, fixes #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 3, 2015
1 parent 0dc69df commit ecddb56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/css-parse.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
if (node.parent) {
var ss = node.previous ? node.previous.end : node.parent.start;
t = text.substring(ss, node.start-1);
t = t.replace(this._rx.multipleSpaces, ' ');
// TODO(sorvell): ad hoc; make selector include only after last ;
// helps with mixin syntax
t = t.substring(t.lastIndexOf(';')+1);
Expand Down Expand Up @@ -162,6 +163,7 @@
mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim,
varApply: /[^;:]*?:[^;]*var[^;]*(?:[;\n]|$)?/gim,
keyframesRule: /^@[^\s]*keyframes/,
multipleSpaces: /\s+/g
},

VAR_START: '--',
Expand Down
17 changes: 17 additions & 0 deletions test/unit/css-parse.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
}
/* comment */
</style>

<style id="multiple-spaces">
.foo .bar {}
.foo .bar {}
.foo


.bar {}
</style>
<script>

function sanitizeCss(text) {
Expand Down Expand Up @@ -119,6 +128,14 @@
assert.equal(result, '.stuff { background: red; }', 'unexpected stringified output');
});

test('multiple consequent spaces in CSS selector', function() {
var s4 = document.querySelector('#multiple-spaces');
var t = css.parse(s4.textContent);
assert.equal(t.rules[0].selector, '.foo .bar');
assert.equal(t.rules[1].selector, '.foo .bar');
assert.equal(t.rules[2].selector, '.foo .bar');
});

});
</script>

Expand Down

0 comments on commit ecddb56

Please sign in to comment.