From edd95fc4df8d6c539bfe21881e922fa75f9c5b69 Mon Sep 17 00:00:00 2001 From: Aleksei Gusev Date: Sat, 7 Apr 2018 20:35:29 +0300 Subject: [PATCH] Fix handling regex symbols in tests path on Windows --- CHANGELOG.md | 2 ++ integration-tests/__tests__/regex_(char_in_path.test.js | 3 --- packages/jest-regex-util/src/__tests__/index.test.js | 4 ++++ packages/jest-regex-util/src/index.js | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6871fc0ca351..db3aa0fef0e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/integration-tests/__tests__/regex_(char_in_path.test.js b/integration-tests/__tests__/regex_(char_in_path.test.js index cd4c22d78f20..2ca1db2c7d97 100644 --- a/integration-tests/__tests__/regex_(char_in_path.test.js +++ b/integration-tests/__tests__/regex_(char_in_path.test.js @@ -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', []); diff --git a/packages/jest-regex-util/src/__tests__/index.test.js b/packages/jest-regex-util/src/__tests__/index.test.js index 87dc1801837a..a15eaa77d1e6 100644 --- a/packages/jest-regex-util/src/__tests__/index.test.js +++ b/packages/jest-regex-util/src/__tests__/index.test.js @@ -39,5 +39,9 @@ describe('replacePathSepForRegex()', () => { 'a\\\\\\\\\\.dotfile', ); }); + + it('should not escape an escaped regexp symbol', () => { + expect(replacePathSepForRegex('b\\(86')).toBe('b\\(86'); + }); }); }); diff --git a/packages/jest-regex-util/src/index.js b/packages/jest-regex-util/src/index.js index e452d15b9b8d..635a1931f0ff 100644 --- a/packages/jest-regex-util/src/index.js +++ b/packages/jest-regex-util/src/index.js @@ -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; };