Skip to content

String#startsWith should throw when a regular expression is passed instead of a string #167

@mathiasbynens

Description

@mathiasbynens

This implementation fails the following tests taken from https://github.com/mathiasbynens/String.prototype.startsWith/blob/master/tests/tests.js:

assertThrows(function() { '[a-z]+(bar)?'.startsWith(/[a-z]+/); }, TypeError);
assertThrows(function() { '[a-z]+(bar)?'.startsWith(/(bar)?/); }, TypeError);
assertThrows(function() { '[a-z]+/(bar)?/'.startsWith(/(bar)?/); }, TypeError);

The same goes for endsWith.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions