From 0d0fee369a433ad14650784273036f33fc0abe7f Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 31 Mar 2024 18:40:48 +0800 Subject: [PATCH] Fix escaping of \u0000 and a standalone surrogate - ref: https://www.w3.org/TR/css-syntax-3/#consume-escaped-code-point --- parse-css.js | 2 +- tests.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parse-css.js b/parse-css.js index efbfdf3..489d040 100644 --- a/parse-css.js +++ b/parse-css.js @@ -362,7 +362,7 @@ function tokenize(str) { } if(whitespace(next())) consume(); var value = parseInt(digits.map(function(x){return String.fromCharCode(x);}).join(''), 16); - if( value > maximumallowedcodepoint ) value = 0xfffd; + if (value === 0x0 || between(value, 0xd800, 0xdfff) || value > maximumallowedcodepoint ) value = 0xfffd; return value; } else if(eof()) { return 0xfffd; diff --git a/tests.js b/tests.js index cb729bc..4c3bd6d 100644 --- a/tests.js +++ b/tests.js @@ -398,6 +398,15 @@ var TESTS = [ "value": "\uFFFD" }, ] + }, { + parser: '', + css: `\\20000 \\0 \\D800 \\DFFF \\110000 `, + expected: [ + { + "type": "IDENT", + "value": "\u{20000}\uFFFD\uFFFD\uFFFD\uFFFD" + }, + ] } ];