Regex change in #1315 leads to failure of matches for Windows paths
See original GitHub issueIn #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:
- Created 6 years ago
- Reactions:4
- Comments:8 (6 by maintainers)
Top GitHub Comments
@GAntoine I can also test it for you on my Windows machine if you need it.
@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.