Broken regular expression in Windows exclusionList.js path separator replacement
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
On Windows, I get an error when running react-native start
:
Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class. Run CLI with --verbose flag for more details.
SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
The Fix
function escapeRegExp(pattern) {
if (Object.prototype.toString.call(pattern) === '[object RegExp]') {
- return pattern.source.replace(/\//g, path.sep);
+ return pattern.source.replace(/\//g, '\\' + path.sep);
} else if (typeof pattern === 'string') {
var escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
// convert the '/' into an escaped local file separator
return escaped.replace(/\//g, '\\' + path.sep);
#-----------------------------------^ The replace method above should also escape `path.sep`
If you look at line 22 of exclusionList.js you’ll see it replaces /
with "\\" + path.sep
but on line 18 it replaces the source with only path.sep
. Instead it should also replace it with "\\" + path.sep
.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Node.js regex: exclude path separator while matching files
Here I tried excluding the path separator with a negative lookahead, so that subfolders of AnimalLib could not be selected. I am on...
Read more >PHP Regular Expressions - W3Schools
The preg_replace() function will replace all of the matches of the pattern in a string with another string. Example. Use a case-insensitive regular...
Read more >Regular expression - Wikipedia
A regular expression is a sequence of characters that specifies a search pattern in text. ... Regular expressions are used in search engines,...
Read more >Regular Expressions :: Eloquent JavaScript
In this chapter, I will discuss one such tool, regular expressions. Regular expressions are a way to describe patterns in string data. They...
Read more >RegExp - JavaScript - MDN Web Docs - Mozilla
Chrome Edge
RegExp Full support. Chrome1. Toggle history Full support. Edge12. Toggle history
@@match Full support. Chrome50. Toggle history Full support. Edge13. Toggle history
@@matchAll Full...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@saurabhbh21 the Regex in the
node_modules
files is not relevant to this issue unless they’re being loaded directly into your Metro configuration, like in theblacklist/blocklist
. I think you’re facing some other problem.Can you send a PR?