From 0aa6d3b4636e7b4e668935201de068d87bd39ab5 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 20 Apr 2021 20:27:07 +0300 Subject: [PATCH] read css escapes per spec --- global.css | 5 +++-- js/csslint/parserlib.js | 10 ++++++++-- js/dom.js | 3 +-- tools/test.js | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/global.css b/global.css index 4c52364f..f267be01 100644 --- a/global.css +++ b/global.css @@ -1,6 +1,7 @@ -html#stylus #header *:not(#\0transition-suppressor) { +html#stylus #header *:not(#\1transition-suppressor) { /* This suppresses a bug in all? browsers: they apply transitions during page load. - * Using an increased specificity to override sane selectors in user styles. */ + * Using an increased specificity to override sane selectors in user styles. + * Using \1 to simplify js code because \0 is converted to \xFFFD per spec. */ transition: none !important; } body { diff --git a/js/csslint/parserlib.js b/js/csslint/parserlib.js index 6f437be4..7c6375bd 100644 --- a/js/csslint/parserlib.js +++ b/js/csslint/parserlib.js @@ -3014,8 +3014,14 @@ self.parserlib = (() => { } readEscape() { - const cp = this._reader.readMatch(/[0-9a-f]{1,6}\b\s*/iy); - return cp ? String.fromCodePoint(parseInt(cp, 16)) : this._reader.read(); + let res = this._reader.readMatch(/[0-9a-f]{1,6}\s?/iy); + if (res) { + res = parseInt(res, 16); + res = String.fromCodePoint(res && res <= 0x10FFFF ? res : 0xFFFD); + } else { + res = this._reader.read(); + } + return res; } /** diff --git a/js/dom.js b/js/dom.js index d4111554..ff2390c9 100644 --- a/js/dom.js +++ b/js/dom.js @@ -440,8 +440,7 @@ async function waitForSheet({ window.on('load', () => { const {sheet} = $('link[href^="global.css"]'); for (let i = 0, rule; (rule = sheet.cssRules[i]); i++) { - // Not using \0 in the id as it's converted to \xFFFD, probably a bug - if (/#.transition-suppressor/.test(rule.selectorText)) { + if (/#\\1\s?transition-suppressor/.test(rule.selectorText)) { sheet.deleteRule(i); break; } diff --git a/tools/test.js b/tools/test.js index abee1c79..f2fc3568 100644 --- a/tools/test.js +++ b/tools/test.js @@ -7,7 +7,7 @@ testGlobalCss(); function testGlobalCss() { const css = fs.readFileSync('global.css', {encoding: 'utf8'}); const ERR = 'global.css: missing the transition suppressor rule'; - const RX_SUPPRESSOR = /[^{}]+#\\0transition-suppressor[^{}]+{\s*transition:\s*none\s*!\s*important/i; + const RX_SUPPRESSOR = /[^{}]+#\\1\s?transition-suppressor[^{}]+{\s*transition:\s*none\s*!\s*important/i; const RX_COMMENT = /\/\*([^*]|\*(?!\/))*(\*\/|$)/g; if (!RX_SUPPRESSOR.test(css.replace(RX_COMMENT, ''))) { console.error(ERR);