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.

Regex change in #1315 leads to failure of matches for Windows paths

See original GitHub issue

In #1315 , a path matching regex was changed to prevent crashes on Windows where an invalid regex would be created (due to missing escapes for backslashes).

The changed code was in runTests.js: Original regex: definitions${path.sep}npm${path.sep}(\@[^${path.sep}]*${path.sep})?[^${path.sep}]*${path.sep}?

The change just replaced all path.sep with /.

The problem now is, that the regex will not match any paths returned by Windows anymore, because they natively contain backslashes.

In my opinion there are 2 feasible approaches to fix the “fix” properly:

(1) Use the original regex, but escape path.sep properly in case it is a backslash:

const escapedPathSep = path.sep === '\\' ? '\\\\' : path.sep;
... `definitions${escapedPathSep}npm${escapedPathSep}(\@[^${escapedPathSep}]*${escapedPathSep})?[^${escapedPathSep}]*${escapedPathSep}?`

(2) Normalize the path so that it only contains slashes:

`definitions${path.sep}npm${path.sep}(\@[^${path.sep}]*${path.sep})?[^${path.sep}]*${path.sep}?`.replace('\\', '')

(1) would be the most compatible solution as (2) might break if paths explicitly contain backslashes on Unix filesystems.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ebrearleycommented, Oct 12, 2017

@GAntoine I can also test it for you on my Windows machine if you need it.

1reaction
GAntoinecommented, Oct 12, 2017

@HyperBrain I’m going to throw together a fix for this bug. I’ll ping you when the PR is up, since I’ll need someone on a windows system to test the fix, if that’s alright with you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regular expression to match a valid absolute Windows ...
I found a better solution to this problem that does not require regular expressions. The solution is to use an improved folder browser,...
Read more >
Lesson 1: Regular expression fails to match Windows paths
I saw that while converting paths to string, the forward slashes got automatically changed to backslashes. Changing the regular expression to r' ...
Read more >
RXXR2 regular expression static analyzer - GitHub Gist
This regex matches FQDNs plus domains starting with an or containing asterisk. ... Regular Expression to validate file path and extension.
Read more >
8.18. Validate Windows Paths - Regular Expressions ... - O'Reilly
Problem. You want to check whether a string looks like a valid path to a folder or file on the Microsoft Windows operating...
Read more >
Regex match failing in GNU grep on Windows Server
Problem 1: Your pattern begins with a hyphen, which makes it ambiguous to grep. Is it a command line option, or is it...
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