question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken regular expression in Windows exclusionList.js path separator replacement

See original GitHub issue

Do 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Slapboxcommented, Jul 2, 2022

@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 the blacklist/blocklist. I think you’re facing some other problem.

1reaction
cpojercommented, Jul 25, 2020

Can you send a PR?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found