Added support for short unicode escape sequences, fixes #2650

This commit is contained in:
Nazar Mokrynskyi 2015-11-01 06:11:33 +01:00
parent 30da1b3d90
commit 2c87145ccc
2 changed files with 45 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 = this._expandUnicodeEscapes(t);
// TODO(sorvell): ad hoc; make selector include only after last ;
// helps with mixin syntax
t = t.substring(t.lastIndexOf(';')+1);
@ -89,6 +90,18 @@ Polymer.CssParse = (function() {
return node;
},
// conversion of sort unicode escapes with spaces like `\33 ` (and longer) into
// expanded form that doesn't require trailing space `\000033`
_expandUnicodeEscapes : function(s) {
return s.replace(/\\([0-9a-f]{1,6})\s/gi, function() {
var code = arguments[1], repeat = 6 - code.length;
while (repeat--) {
code = '0' + code;
}
return '\\' + code;
});
},
// stringify parsed css.
stringify: function(node, preserveProperties, text) {
text = text || '';

View File

@ -60,6 +60,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
/* comment */
</style>
<style id="short-escape-sequence">
.\33 d-model {
border-top: 3px solid red;
}
.\a33 d-model {
border-top: 3px solid red;
}
.\b333 d-model {
border-top: 3px solid red;
}
.\c3333 d-model {
border-top: 3px solid red;
}
.\d33333 d-model {
border-top: 3px solid red;
}
.\e33333d-model {
border-top: 3px solid red;
}
</style>
<script>
function sanitizeCss(text) {
@ -119,6 +140,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assert.equal(result, '.stuff { background: red; }', 'unexpected stringified output');
});
test('short escape sequences', function() {
var s3 = document.querySelector('#short-escape-sequence');
var t = css.parse(s3.textContent);
assert.equal(t.rules[0].selector, '.\\000033d-model');
assert.equal(t.rules[1].selector, '.\\000a33d-model');
assert.equal(t.rules[2].selector, '.\\00b333d-model');
assert.equal(t.rules[3].selector, '.\\0c3333d-model');
assert.equal(t.rules[4].selector, '.\\d33333d-model');
assert.equal(t.rules[5].selector, '.\\e33333d-model');
});
});
</script>