mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibJS: Fix \x escapes of bytes with high bit set
With this, typing `"\xff"` into Browser's console no longer makes the app crash. While here, also make the \u handler call append_codepoint() instead of calling an overload where it's not immediately clear which overload is getting called. This has no behavior change.
This commit is contained in:
parent
01522b8d71
commit
9e32ad6c99
2 changed files with 4 additions and 2 deletions
|
@ -3,6 +3,7 @@ test("hex escapes", () => {
|
||||||
expect("X55").toBe("X55");
|
expect("X55").toBe("X55");
|
||||||
expect(`\x55`).toBe("U");
|
expect(`\x55`).toBe("U");
|
||||||
expect(`\X55`).toBe("X55");
|
expect(`\X55`).toBe("X55");
|
||||||
|
expect("\xff").toBe(String.fromCharCode(0xff));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("unicode escapes", () => {
|
test("unicode escapes", () => {
|
||||||
|
@ -10,4 +11,5 @@ test("unicode escapes", () => {
|
||||||
expect(`\u26a0`).toBe("⚠");
|
expect(`\u26a0`).toBe("⚠");
|
||||||
expect("\u{1f41e}").toBe("🐞");
|
expect("\u{1f41e}").toBe("🐞");
|
||||||
expect(`\u{1f41e}`).toBe("🐞");
|
expect(`\u{1f41e}`).toBe("🐞");
|
||||||
|
expect("\u00ff").toBe(String.fromCharCode(0xff));
|
||||||
});
|
});
|
||||||
|
|
|
@ -136,7 +136,7 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
auto digit2 = m_value[++i];
|
auto digit2 = m_value[++i];
|
||||||
if (!isxdigit(digit1) || !isxdigit(digit2))
|
if (!isxdigit(digit1) || !isxdigit(digit2))
|
||||||
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
||||||
builder.append(static_cast<char>(hex2int(digit1) * 16 + hex2int(digit2)));
|
builder.append_codepoint(hex2int(digit1) * 16 + hex2int(digit2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'u': {
|
case 'u': {
|
||||||
|
@ -174,7 +174,7 @@ String Token::string_value(StringValueStatus& status) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append({ &code_point, 1 });
|
builder.append_codepoint(code_point);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue