Skip to content

Commit 420bcb4

Browse files
committed
Escape a few RegExps.
1 parent 47e9194 commit 420bcb4

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

apps/rush-lib/src/cli/actions/ChangeAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as os from 'os';
55
import * as path from 'path';
66
import * as child_process from 'child_process';
77
import * as colors from 'colors';
8+
import * as lodash from 'lodash';
89

910
import inquirer = require('inquirer');
1011

@@ -210,7 +211,7 @@ export class ChangeAction extends BaseRushAction {
210211
normalizedFolder = normalizedFolder + '/';
211212
}
212213

213-
const pathRegex: RegExp = new RegExp(`^${normalizedFolder}`, 'i');
214+
const pathRegex: RegExp = new RegExp(`^${lodash.escapeRegExp(normalizedFolder)}`, 'i');
214215
for (const folder of changedFolders) {
215216
if (folder && folder.match(pathRegex)) {
216217
return true;

apps/rush-lib/src/logic/policy/GitEmailPolicy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class GitEmailPolicy {
7373

7474
// If there is a policy, at least one of the RegExp's must match
7575
for (const pattern of rushConfiguration.gitAllowedEmailRegExps) {
76-
const regex: RegExp = new RegExp('^' + pattern + '$', 'i');
76+
const regex: RegExp = new RegExp(`^${pattern}$`, 'i');
7777
if (userEmail.match(regex)) {
7878
return;
7979
}

apps/rush-lib/src/utilities/VersionControl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as child_process from 'child_process';
55
import * as colors from 'colors';
6+
import * as lodash from 'lodash';
67
import { Executable } from '@microsoft/node-core-library';
78

89
const DEFAULT_BRANCH: string = 'master';
@@ -59,7 +60,7 @@ export class VersionControl {
5960
const output: string = child_process.execSync(
6061
`git diff ${targetBranch}... --name-only --no-renames --diff-filter=A`
6162
).toString();
62-
const regex: RegExp | undefined = pathPrefix ? new RegExp(`^${pathPrefix}`, 'i') : undefined;
63+
const regex: RegExp | undefined = pathPrefix ? new RegExp(`^${lodash.escapeRegExp(pathPrefix)}`, 'i') : undefined;
6364
return output.split('\n').map((line) => {
6465
if (line) {
6566
const trimmedLine: string = line.trim();

0 commit comments

Comments
 (0)