Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw TypeError if regex is passed to String.prototype.startsWith #755

Closed
jasonwilliams opened this issue Oct 1, 2020 · 1 comment · Fixed by #782
Closed

Throw TypeError if regex is passed to String.prototype.startsWith #755

jasonwilliams opened this issue Oct 1, 2020 · 1 comment · Fixed by #782
Labels
E-Easy Easy enhancement New feature or request good first issue Good for newcomers

Comments

@jasonwilliams
Copy link
Member

jasonwilliams commented Oct 1, 2020

In our implementation of String.prototype.startsWith we're not type checking the argument and blindly coercing it into a string.
https://github.com/boa-dev/boa/blob/master/boa/src/builtins/string/mod.rs#L301

We should match on the value (or if let) and if its a regular expression throw a type error:

ctx.throw_type_error("First argument to String.prototype.startsWith must not be a regular expression")?;

There should be a test also

Same here: https://github.com/boa-dev/boa/blob/master/boa/src/builtins/string/mod.rs#L344
and here: https://github.com/boa-dev/boa/blob/master/boa/src/builtins/string/mod.rs#L390

Example JS

const str1 = 'Saturday night plans';
console.log(str1.startsWith(/saturday/));

Contributing: https://github.com/boa-dev/boa/blob/master/CONTRIBUTING.md
Debugging: https://github.com/boa-dev/boa/blob/master/docs/debugging.md

@jasonwilliams jasonwilliams added enhancement New feature or request good first issue Good for newcomers E-Easy Easy labels Oct 1, 2020
@pt2121
Copy link
Contributor

pt2121 commented Oct 2, 2020

Can I take a stab at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-Easy Easy enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants