Skip to content

Commit 734c72e

Browse files
committed
Escape used-provided input to glob
This fixes #946 [1]. [1] #946
1 parent 3f3c48c commit 734c72e

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

features/issues/946.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/946
2+
3+
Feature: spec names containing glob specific characters
4+
Scenario: spec names containing glob specific characters
5+
Given a file named "cypress/e2e/[foo].feature" with:
6+
"""
7+
Feature: a feature
8+
Scenario: a scenario
9+
Given a step
10+
"""
11+
And a file named "cypress/e2e/[foo].js" with:
12+
"""
13+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
14+
Given("a step", function() {})
15+
"""
16+
When I run cypress
17+
Then it passes

lib/step-definitions.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "path";
22

3-
import { glob } from "glob";
3+
import glob from "glob";
44

55
import util from "util";
66

@@ -26,7 +26,7 @@ export async function getStepDefinitionPaths(
2626
return (
2727
await Promise.all(
2828
stepDefinitionPatterns.map((pattern) =>
29-
glob(pattern, { nodir: true, windowsPathsNoEscape: true })
29+
glob.glob(pattern, { nodir: true, windowsPathsNoEscape: true })
3030
)
3131
)
3232
).reduce((acum, el) => acum.concat(el), []);
@@ -82,11 +82,14 @@ export function getStepDefinitionPatternsPost10(
8282
throw new Error(`${filepath} is not inside ${projectRoot}`);
8383
}
8484

85-
const filepathReplacement = trimFeatureExtension(
86-
path.relative(
87-
configuration.preprocessor.implicitIntegrationFolder,
88-
filepath
89-
)
85+
const filepathReplacement = glob.escape(
86+
trimFeatureExtension(
87+
path.relative(
88+
configuration.preprocessor.implicitIntegrationFolder,
89+
filepath
90+
)
91+
),
92+
{ windowsPathsNoEscape: true }
9093
);
9194

9295
debug(`replacing [filepath] with ${util.inspect(filepathReplacement)}`);
@@ -138,8 +141,9 @@ export function getStepDefinitionPatternsPre10(
138141
throw new Error(`${filepath} is not inside ${fullIntegrationFolder}`);
139142
}
140143

141-
const filepathReplacement = trimFeatureExtension(
142-
path.relative(fullIntegrationFolder, filepath)
144+
const filepathReplacement = glob.escape(
145+
trimFeatureExtension(path.relative(fullIntegrationFolder, filepath)),
146+
{ windowsPathsNoEscape: true }
143147
);
144148

145149
debug(`replacing [filepath] with ${util.inspect(filepathReplacement)}`);

0 commit comments

Comments
 (0)