Skip to content

Commit

Permalink
Fix handling regex symbols in tests path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hron committed Apr 7, 2018
1 parent 6979b8e commit edd95fc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
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;
};

0 comments on commit edd95fc

Please sign in to comment.