1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

LibJS: Implement String.prototype.substr according to the spec

Fixes #6325

The JavaScript on the HTML Spec site that caused the crash is:
    window.location.hash.substr(1)

Of course, window.location.hash can be the empty string. The spec allows
for calling substr(1) on an empty string, but our partial implementation
wasn't handling it properly.
This commit is contained in:
Timothy Flynn 2021-04-14 17:46:18 -04:00 committed by Andreas Kling
parent bc9cd55da4
commit b6093ae2e3
2 changed files with 22 additions and 16 deletions

View file

@ -1,6 +1,9 @@
test("basic functionality", () => {
expect(String.prototype.substr).toHaveLength(2);
expect("".substr(1)).toBe("");
expect("".substr()).toBe("");
expect("".substr(-1)).toBe("");
expect("hello friends".substr()).toBe("hello friends");
expect("hello friends".substr(1)).toBe("ello friends");
expect("hello friends".substr(0, 5)).toBe("hello");