From: Dmitry Volyntsev Date: Sat, 23 May 2026 01:32:16 +0000 (-0700) Subject: Parser: fixed string escape lookahead bounds X-Git-Tag: 1.0.0~41 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=cf923a0a9954b0a4f77e110c0b8d393853175b78;p=njs.git Parser: fixed string escape lookahead bounds --- diff --git a/src/njs_parser.c b/src/njs_parser.c index 93811746..c54cd55d 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -9255,7 +9255,9 @@ next_char: cp_pair = 0; } else if (njs_surrogate_any(cp)) { - if (cp <= 0xdbff && src[0] == '\\' && src[1] == 'u') { + if (cp <= 0xdbff && (end - src) >= 2 + && src[0] == '\\' && src[1] == 'u') + { cp_pair = cp; continue; } @@ -9412,7 +9414,9 @@ njs_parser_escape_string_calc_length(njs_parser_t *parser, cp_pair = 0; } else if (njs_surrogate_any(cp)) { - if (cp <= 0xdbff && src[0] == '\\' && src[1] == 'u') { + if (cp <= 0xdbff && (end - src) >= 2 + && src[0] == '\\' && src[1] == 'u') + { cp_pair = cp; continue; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index edbddd79..02ce2c5a 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -8160,6 +8160,12 @@ static njs_unit_test_t njs_test[] = { njs_str("`\\${a}bc"), njs_str("SyntaxError: Unterminated template literal") }, + { njs_str("`\\ud83d`"), + njs_str("�") }, + + { njs_str("`\\ud83d${1}`"), + njs_str("�1") }, + { njs_str("var v = undefined; var u8 = 'α';" "[`undefined${u8}`.length, `undefineQ${u8}`.length]"), njs_str("10,10") },