tc39 / tc39/test262

Coverage for invalid RegExp source

Open
#97 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

coverage missing
Dominant language
JavaScript
Stars
2.8k
Forks
564
Avg merge
3d 7h
Merged PRs (30d)
10

Description

ES5 has the following to say:

The characters / or backslash \ occurring in the pattern shall be escaped in S as necessary to ensure that the String value formed by concatenating the Strings "/", S, "/", and F can be parsed (in an appropriate lexical context) as a RegularExpressionLiteral that behaves identically to the constructed regular expression. For example, if P is "/", then S could be "/" or "\u002F", among other possibilities, but not "/", because /// followed by F would be parsed as a SingleLineComment rather than a RegularExpressionLiteral. If P is the empty String, this specification can be met by letting S be "(?:)"

The key is that var r = new RegExp(str); eval("/" + r.source + "/") should give you a regexp identical to r.

Implementations don't follow this too closely. IE doesn't handle empty string properly. FF/Chrome don't seem to handle "\n" properly. There are probably other interesting cases to be discovered.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the ES5 rule quoted in the issue and the repository's existing RegExp tests. Add coverage for empty strings, newlines, slashes, backslashes, and other invalid or escaping cases, checking that eval("/" + r.source + "/") produces an equivalent regular expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.