Fix for multiple consequent spaces present in CSS selectors, fixes #2670

This commit is contained in:
Nazar Mokrynskyi 2015-11-03 03:07:52 +01:00
parent 0dc69dfbe5
commit ecddb56bc1
2 changed files with 19 additions and 0 deletions

View File

@ -60,6 +60,7 @@ Polymer.CssParse = (function() {
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);
@ -162,6 +163,7 @@ Polymer.CssParse = (function() {
mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim,
varApply: /[^;:]*?:[^;]*var[^;]*(?:[;\n]|$)?/gim,
keyframesRule: /^@[^\s]*keyframes/,
multipleSpaces: /\s+/g
},
VAR_START: '--',

View File

@ -60,6 +60,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
/* comment */
</style>
<style id="multiple-spaces">
.foo .bar {}
.foo .bar {}
.foo
.bar {}
</style>
<script>
function sanitizeCss(text) {
@ -119,6 +128,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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>