Skip to content

Commit edd95fc

Browse files
committed
Fix handling regex symbols in tests path on Windows
1 parent 6979b8e commit edd95fc

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
([#5720](https://github.com/facebook/jest/pull/5720))
7474
* `[pretty-format]` Handle React fragments better
7575
([#5816](https://github.com/facebook/jest/pull/5816))
76+
* `[jest-regex-util]` Fix handling regex symbols in tests path on Windows
77+
([#5941](https://github.com/facebook/jest/pull/5941))
7678

7779
### Chore & Maintenance
7880

integration-tests/__tests__/regex_(char_in_path.test.js

-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
*/
99
'use strict';
1010

11-
const SkipOnWindows = require('../../scripts/SkipOnWindows');
1211
const runJest = require('../runJest');
1312

1413
describe('Regex Char In Path', () => {
15-
SkipOnWindows.suite();
16-
1714
it('parses paths containing regex chars correctly', () => {
1815
const {json} = runJest.json('regex-(char-in-path', []);
1916

packages/jest-regex-util/src/__tests__/index.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@ describe('replacePathSepForRegex()', () => {
3939
'a\\\\\\\\\\.dotfile',
4040
);
4141
});
42+
43+
it('should not escape an escaped regexp symbol', () => {
44+
expect(replacePathSepForRegex('b\\(86')).toBe('b\\(86');
45+
});
4246
});
4347
});

packages/jest-regex-util/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const escapeStrForRegex = (string: string) =>
2323

2424
export const replacePathSepForRegex = (string: string) => {
2525
if (path.sep === '\\') {
26-
return string.replace(/(\/|\\(?!\.))/g, '\\\\');
26+
return string.replace(/(\/|\\(?![[\]{}()*+?.^$|]))/g, '\\\\');
2727
}
2828
return string;
2929
};

0 commit comments

Comments
 (0)