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 d331af8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
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 d331af8

Please sign in to comment.