mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #2664 from nazar-pc/fix-for-unicode-escape-sequences-in-css-selectors
Added support for short unicode escape sequences, fixes #2650
This commit is contained in:
commit
174b77b645
@ -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 || '';
|
||||
|
@ -68,6 +68,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
someProperty: thatMustNotShowUp
|
||||
}*/
|
||||
</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) {
|
||||
@ -127,6 +148,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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user