From 571c7f28510c2b92285b70993d067ea3ac1c7a3a Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 12 Jul 2019 15:48:34 +0300 Subject: [PATCH 1/2] fix: escape the regex for the path to the entry module of application --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2ed399dc..3d24db39 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const path = require("path"); const { existsSync } = require("fs"); +const escapeRegExp = require("escape-string-regexp"); const { ANDROID_APP_PATH } = require("./androidProjectHelpers"); const { getPackageJson, @@ -62,8 +63,7 @@ exports.getAppPath = (platform, projectDir) => { exports.getEntryPathRegExp = (appFullPath, entryModule) => { const entryModuleFullPath = path.join(appFullPath, entryModule); - // Windows paths contain `\`, so we need to convert each of the `\` to `\\`, so it will be correct inside RegExp - const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\"); + const escapedPath = escapeRegExp(entryModuleFullPath); return new RegExp(escapedPath); } From 82063e287c6f0574669a5e53b2c5b3c5ba872f98 Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 12 Jul 2019 15:55:17 +0300 Subject: [PATCH 2/2] chore: add unit tests --- index.spec.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.spec.ts b/index.spec.ts index eda14f88..d97dc20d 100644 --- a/index.spec.ts +++ b/index.spec.ts @@ -61,7 +61,7 @@ describe('index', () => { path.join = originalPathJoin; }); - it('returns RegExp that matches Windows', () => { + it('returns RegExp that works with Windows paths', () => { const appPath = "D:\\Work\\app1\\app"; path.join = path.win32.join; const regExp = getEntryPathRegExp(appPath, entryModule); @@ -74,5 +74,19 @@ describe('index', () => { const regExp = getEntryPathRegExp(appPath, entryModule); expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true); }); + + it('returns RegExp that works with Windows paths with special symbol in path', () => { + const appPath = "D:\\Work\\app1\\app (2)"; + path.join = path.win32.join; + const regExp = getEntryPathRegExp(appPath, entryModule); + expect(!!regExp.exec(`${appPath}\\${entryModule}`)).toBe(true); + }); + + it('returns RegExp that works with POSIX paths with special symbol in path', () => { + const appPath = "/usr/local/lib/app1/app (2)"; + path.join = path.posix.join; + const regExp = getEntryPathRegExp(appPath, entryModule); + expect(!!regExp.exec(`${appPath}/${entryModule}`)).toBe(true); + }); }); });