Skip to content

Commit 86126e5

Browse files
committed
fix: command construction
1 parent bc5b923 commit 86126e5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

dev-packages/e2e-tests/run.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { registrySetup } from './registrySetup';
1111
interface SentryTestVariant {
1212
'build-command': string;
1313
'assert-command'?: string;
14-
label: string;
14+
label?: string;
1515
}
1616

1717
interface PackageJson {
@@ -74,7 +74,7 @@ function asyncExec(
7474
function findMatchingVariant(variants: SentryTestVariant[], variantLabel: string): SentryTestVariant | undefined {
7575
const variantLabelLower = variantLabel.toLowerCase();
7676

77-
return variants.find(variant => variant.label.toLowerCase().includes(variantLabelLower));
77+
return variants.find(variant => variant.label?.toLowerCase().includes(variantLabelLower));
7878
}
7979

8080
async function getVariantBuildCommand(
@@ -97,7 +97,7 @@ async function getVariantBuildCommand(
9797
return {
9898
buildCommand: matchingVariant['build-command'] || 'pnpm test:build',
9999
assertCommand: matchingVariant['assert-command'] || 'pnpm test:assert',
100-
testLabel: matchingVariant.label,
100+
testLabel: matchingVariant.label || testAppPath,
101101
matchedVariantLabel: matchingVariant.label,
102102
};
103103
}
@@ -136,7 +136,7 @@ async function run(): Promise<void> {
136136

137137
// Handle --variant=<value> format
138138
if (flag.startsWith('--variant=')) {
139-
const value = flag.split('=')[1];
139+
const value = flag.slice('--variant='.length);
140140
const trimmedValue = value?.trim();
141141
if (trimmedValue) {
142142
variantLabel = trimmedValue;
@@ -224,8 +224,24 @@ async function run(): Promise<void> {
224224
await asyncExec(`volta run ${buildCommand}`, { env, cwd });
225225

226226
console.log(`Testing ${testLabel}...`);
227-
// Pass command and arguments as an array to prevent command injection
228-
const testCommand = ['volta', 'run', ...assertCommand.split(' '), ...testFlags];
227+
// Pass command as a string to support shell features (env vars, operators like &&)
228+
// This matches how buildCommand is handled for consistency
229+
// Properly quote test flags to preserve spaces and special characters
230+
const quotedTestFlags = testFlags.map(flag => {
231+
// If flag contains spaces or special shell characters, quote it
232+
if (
233+
flag.includes(' ') ||
234+
flag.includes('"') ||
235+
flag.includes("'") ||
236+
flag.includes('$') ||
237+
flag.includes('`')
238+
) {
239+
// Escape single quotes and wrap in single quotes (safest for shell)
240+
return `'${flag.replace(/'/g, "'\\''")}'`;
241+
}
242+
return flag;
243+
});
244+
const testCommand = `volta run ${assertCommand}${quotedTestFlags.length > 0 ? ` ${quotedTestFlags.join(' ')}` : ''}`;
229245
await asyncExec(testCommand, { env, cwd });
230246

231247
// clean up (although this is tmp, still nice to do)

0 commit comments

Comments
 (0)