Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix handling regex symbols in tests path on Windows
  • Loading branch information
hron committed Apr 7, 2018
commit edd95fc4df8d6c539bfe21881e922fa75f9c5b69
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
([#5720](https://github.com/facebook/jest/pull/5720))
* `[pretty-format]` Handle React fragments better
([#5816](https://github.com/facebook/jest/pull/5816))
* `[jest-regex-util]` Fix handling regex symbols in tests path on Windows
([#5941](https://github.com/facebook/jest/pull/5941))

### Chore & Maintenance

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/regex_(char_in_path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
*/
'use strict';

const SkipOnWindows = require('../../scripts/SkipOnWindows');
const runJest = require('../runJest');

describe('Regex Char In Path', () => {
SkipOnWindows.suite();

it('parses paths containing regex chars correctly', () => {
const {json} = runJest.json('regex-(char-in-path', []);

Expand Down
4 changes: 4 additions & 0 deletions packages/jest-regex-util/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ describe('replacePathSepForRegex()', () => {
'a\\\\\\\\\\.dotfile',
);
});

it('should not escape an escaped regexp symbol', () => {
expect(replacePathSepForRegex('b\\(86')).toBe('b\\(86');
});
});
});
2 changes: 1 addition & 1 deletion packages/jest-regex-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const escapeStrForRegex = (string: string) =>

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