1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:28:11 +00:00

LibJS: Use GenericLexer for Token::string_value()

This is, and I can't stress this enough, a lot better than all the
manual bounds checking and indexing that was going on before.

Also fixes a small bug where "\u{}" wouldn't get rejected as invalid
unicode escape sequence.
This commit is contained in:
Linus Groh 2020-10-28 09:29:11 +00:00 committed by Andreas Kling
parent 1daa5158eb
commit 3dbf4c62b0
2 changed files with 114 additions and 151 deletions

View file

@ -4,6 +4,11 @@ test("hex escapes", () => {
expect(`\x55`).toBe("U");
expect(`\X55`).toBe("X55");
expect("\xff").toBe(String.fromCharCode(0xff));
expect("'\\x'").not.toEval();
expect("'\\x1'").not.toEval();
expect("'\\xz'").not.toEval();
expect("'\\xzz'").not.toEval();
expect("'\\x🐞'").not.toEval();
});
test("unicode escapes", () => {
@ -12,6 +17,18 @@ test("unicode escapes", () => {
expect("\u{1f41e}").toBe("🐞");
expect(`\u{1f41e}`).toBe("🐞");
expect("\u00ff").toBe(String.fromCharCode(0xff));
expect("'\\u'").not.toEval();
expect("'\\u1'").not.toEval();
expect("'\\uf'").not.toEval();
expect("'\\u123'").not.toEval();
expect("'\\u123z'").not.toEval();
expect("'\\uz'").not.toEval();
expect("'\\uzz'").not.toEval();
expect("'\\uzzzz'").not.toEval();
expect("'\\u{'").not.toEval();
expect("'\\u{}'").not.toEval();
expect("'\\u{z}'").not.toEval();
expect("'\\u🐞'").not.toEval();
});
describe("octal escapes", () => {