Fix string with pattern where regular expression contains a double quote #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For the string rule with pattern, if the regular expression contains a double quote an invalid token error occurs in the message field. This is because the RegExp.toString does not escape the internal double quote and the construction of the message concatenates double quotes to this value.
You can test this with sample regular expression /^[a-z0-9 .-'?!":;\/,_]+$/i
In this pull request, when constructing the message I replace the double quote with an escaped version, but due to the internal processing I have to also escape the escape character (\").
Jest reports 100% success for all tests plus the additional test I added.