Skip to content

Commit 1562a25

Browse files
committed
sanitize file names written to filesystem
1 parent 1f60128 commit 1562a25

File tree

1 file changed

+12
-4
lines changed
  • packages/selenium-side-runner/src

1 file changed

+12
-4
lines changed

packages/selenium-side-runner/src/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function runProject(project) {
207207
)
208208
)
209209
}
210-
projectPath = `side-suite-${project.name}`
210+
projectPath = `side-suite-${sanitizeFileName(project.name)}`
211211
rimraf.sync(projectPath)
212212
fs.mkdirSync(projectPath)
213213
fs.writeFileSync(
@@ -251,17 +251,21 @@ function runProject(project) {
251251
? ''
252252
: 'beforeEach(() => {vars = {};});afterEach(async () => (cleanup()));'
253253
writeJSFile(
254-
path.join(projectPath, suite.name),
254+
path.join(projectPath, sanitizeFileName(suite.name)),
255255
`// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${
256256
code.globalConfig
257257
}${suite.code}${cleanup}`
258258
)
259259
} else if (suite.tests.length) {
260-
fs.mkdirSync(path.join(projectPath, suite.name))
260+
fs.mkdirSync(path.join(projectPath, sanitizeFileName(suite.name)))
261261
// parallel suite
262262
suite.tests.forEach(test => {
263263
writeJSFile(
264-
path.join(projectPath, suite.name, test.name),
264+
path.join(
265+
projectPath,
266+
sanitizeFileName(suite.name),
267+
sanitizeFileName(test.name)
268+
),
265269
`// This file was generated using Selenium IDE\nconst tests = require("../commons.js");${
266270
code.globalConfig
267271
}${test.code}`
@@ -366,6 +370,10 @@ function writeJSFile(name, data, postfix = '.test.js') {
366370
fs.writeFileSync(`${name}${postfix}`, beautify(data, { indent_size: 2 }))
367371
}
368372

373+
function sanitizeFileName(name) {
374+
return name.replace(/([^a-z0-9 ._-]+)/gi, '')
375+
}
376+
369377
const projects = [
370378
...program.args.reduce((projects, project) => {
371379
glob.sync(project).forEach(p => {

0 commit comments

Comments
 (0)