Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(cli): prevent shell injection in --only-changed ref argument (#40657)
Sebastien Tardifcc8ba29c22f1
diff --git a/packages/playwright/src/runner/vcs.ts b/packages/playwright/src/runner/vcs.tsindex b5af2e9e05..dd2ec2f657 100644--- a/packages/playwright/src/runner/vcs.ts+++ b/packages/playwright/src/runner/vcs.ts@@ -20,10 +20,10 @@ import path from 'path';import { cc } from '../common';export async function detectChangedTestFiles(baseCommit: string, configDir: string): Promise<Set<string>> {- function gitFileList(command: string) {+ function gitFileList(args: string[]) {try {- return childProcess.execSync(- `git ${command}`,+ return childProcess.execFileSync(+ 'git', args,{ encoding: 'utf-8', stdio: 'pipe', cwd: configDir }).split('\n').filter(Boolean);} catch (_error) {@@ -31,7 +31,7 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: striconst unknownRevision = error.output.some(line => line?.includes('unknown revision'));if (unknownRevision) {- const isShallowClone = childProcess.execSync('git rev-parse --is-shallow-repository', { encoding: 'utf-8', stdio: 'pipe', cwd: configDir }).trim() === 'true';+ const isShallowClone = childProcess.execFileSync('git', ['rev-parse', '--is-shallow-repository'], { encoding: 'utf-8', stdio: 'pipe', cwd: configDir }).trim() === 'true';if (isShallowClone) {throw new Error([`The repository is a shallow clone and does not have '${baseCommit}' available locally.`,@@ -42,17 +42,17 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: strithrow new Error([`Cannot detect changed files for --only-changed mode:`,- `git ${command}`,+ `git ${args.join(' ')}`,'',...error.output,].join('\n'));}}- const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`).map(file => path.join(configDir, file));+ const untrackedFiles = gitFileList(['ls-files', '--others', '--exclude-standard']).map(file => path.join(configDir, file));- const [gitRoot] = gitFileList('rev-parse --show-toplevel');- const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`).map(file => path.join(gitRoot, file));+ const [gitRoot] = gitFileList(['rev-parse', '--show-toplevel']);+ const trackedFilesWithChanges = gitFileList(['diff', baseCommit, '--name-only']).map(file => path.join(gitRoot, file));return new Set(cc.affectedTestFiles([...untrackedFiles, ...trackedFilesWithChanges]));}