Skip to content

Commit 92c810a

Browse files
committed
escape special chars
1 parent 88b153e commit 92c810a

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

dist/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32533,6 +32533,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3253332533
const core_1 = __nccwpck_require__(2186);
3253432534
const params_1 = __nccwpck_require__(5966);
3253532535
const child_process_1 = __nccwpck_require__(2081);
32536+
const escapeShellValue = (value) => {
32537+
// Escape special characters that could cause shell interpretation issues
32538+
return value.replace(/(["\\'$`!])/g, '\\$1');
32539+
};
3253632540
const run = () => __awaiter(void 0, void 0, void 0, function* () {
3253732541
try {
3253832542
const { additionalAppBinaryIds, additionalAppFiles, androidApiLevel, androidDevice, apiKey, apiUrl, appBinaryId, appFilePath, async, deviceLocale, downloadArtifacts, env, excludeFlows, excludeTags, googlePlay, includeTags, iOSVersion, iosDevice, maestroVersion, name, orientation, retry, workspaceFolder, } = yield (0, params_1.getParameters)();
@@ -32563,16 +32567,21 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
3256332567
let paramsString = Object.keys(params).reduce((acc, key) => {
3256432568
if (!params[key])
3256532569
return acc;
32566-
const needsQuotes = typeof params[key] === 'string' &&
32567-
'"' !== params[key][0] &&
32568-
params[key].includes(' ');
32569-
const value = needsQuotes ? `"${params[key]}"` : params[key];
32570-
return `${acc} --${key} ${value}`;
32570+
const value = typeof params[key] === 'string'
32571+
? escapeShellValue(params[key])
32572+
: params[key];
32573+
const needsQuotes = typeof value === 'string' &&
32574+
!value.startsWith('"') &&
32575+
(value.includes(' ') || value.includes('\\'));
32576+
const finalValue = needsQuotes ? `"${value}"` : value;
32577+
return `${acc} --${key} ${finalValue}`;
3257132578
}, '');
3257232579
if (env && env.length > 0) {
3257332580
env.forEach((e) => {
3257432581
let [key, value] = e.split('=');
32575-
const needsQuotes = '"' !== value[0] && value.includes(' ');
32582+
value = escapeShellValue(value);
32583+
const needsQuotes = !value.startsWith('"') &&
32584+
(value.includes(' ') || value.includes('\\'));
3257632585
if (needsQuotes)
3257732586
value = `"${value}"`;
3257832587
paramsString += ` --env ${key}=${value}`;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "dcd-github-action",
33
"description": "run maestro tests on devicecloud.dev",
44
"author": "devicecloud.dev",
5-
"version": "1.2.0",
5+
"version": "1.2.1",
66
"main": "src/index.ts",
77
"license": "MIT",
88
"engines": {
@@ -24,5 +24,6 @@
2424
"@types/node-fetch": "^2.6.4",
2525
"@vercel/ncc": "^0.36.1",
2626
"typescript": "^5.1.6"
27-
}
27+
},
28+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
2829
}

src/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { setFailed } from '@actions/core';
22
import { getParameters } from './methods/params';
33
import { execSync } from 'child_process';
44

5+
const escapeShellValue = (value: string): string => {
6+
// Escape special characters that could cause shell interpretation issues
7+
return value.replace(/(["\\'$`!])/g, '\\$1');
8+
};
9+
510
const run = async (): Promise<void> => {
611
try {
712
const {
@@ -57,18 +62,25 @@ const run = async (): Promise<void> => {
5762

5863
let paramsString = Object.keys(params).reduce((acc, key) => {
5964
if (!params[key]) return acc;
65+
const value =
66+
typeof params[key] === 'string'
67+
? escapeShellValue(params[key])
68+
: params[key];
6069
const needsQuotes =
61-
typeof params[key] === 'string' &&
62-
'"' !== params[key][0] &&
63-
params[key].includes(' ');
64-
const value = needsQuotes ? `"${params[key]}"` : params[key];
65-
return `${acc} --${key} ${value}`;
70+
typeof value === 'string' &&
71+
!value.startsWith('"') &&
72+
(value.includes(' ') || value.includes('\\'));
73+
const finalValue = needsQuotes ? `"${value}"` : value;
74+
return `${acc} --${key} ${finalValue}`;
6675
}, '');
6776

6877
if (env && env.length > 0) {
6978
env.forEach((e) => {
7079
let [key, value] = e.split('=');
71-
const needsQuotes = '"' !== value[0] && value.includes(' ');
80+
value = escapeShellValue(value);
81+
const needsQuotes =
82+
!value.startsWith('"') &&
83+
(value.includes(' ') || value.includes('\\'));
7284
if (needsQuotes) value = `"${value}"`;
7385
paramsString += ` --env ${key}=${value}`;
7486
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es6",
4+
"lib": ["es2016"],
45
"module": "commonjs",
56
"outDir": "./dist",
67
"rootDir": ".",

0 commit comments

Comments
 (0)