Skip to content

Commit

Permalink
fix(ios): launchArgs quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Dec 18, 2020
1 parent 9b8a7c8 commit 95ee888
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion detox/local-cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const _ = require('lodash');
const cp = require('child_process');
const path = require('path');
const unparse = require('yargs-unparser');
const { parse, quote } = require('./utils/shellQuote');
const splitArgv = require('./utils/splitArgv');
const DetoxRuntimeError = require('../src/errors/DetoxRuntimeError');
const DeviceRegistry = require('../src/devices/DeviceRegistry');
const GenyDeviceRegistryFactory = require('../src/devices/drivers/android/genycloud/GenyDeviceRegistryFactory');
const { loadLastFailedTests, resetLastFailedTests } = require('../src/utils/lastFailedTests');
const { parse, quote } = require('../src/utils/shellQuote');
const { composeDetoxConfig } = require('../src/configuration');
const log = require('../src/utils/logger').child({ __filename });
const { getPlatformSpecificString, printEnvironmentVariables } = require('./utils/misc');
Expand Down
3 changes: 2 additions & 1 deletion detox/src/devices/drivers/ios/tools/AppleSimUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {joinArgs} = require('../../../../utils/argparse');
const exec = require('../../../../utils/exec');
const log = require('../../../../utils/logger').child({ __filename });
const environment = require('../../../../utils/environment');
const { quote } = require('../../../../utils/shellQuote');

class AppleSimUtils {
async setPermissions(udid, bundleId, permissionsObj) {
Expand Down Expand Up @@ -297,7 +298,7 @@ class AppleSimUtils {
}

_joinLaunchArgs(launchArgs) {
return _.map(launchArgs, (v, k) => `-${k} "${v}"`).join(' ').trim();
return quote(_.flatMap(launchArgs, (v, k) => [`-${k}`, v])).trim();
}

async _launchMagically(frameworkPath, udid, bundleId, launchArgs, languageAndLocale) {
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions detox/src/utils/shellQuote.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { quote, parse } = require('./shellQuote');

describe('shellQuote', () => {
describe('.quote(argv)', () => {
it('should not escape safe characters', () => {
expect(quote(['-w', '3'])).toBe('-w 3');
});

it('should escape unsafe characters', () => {
expect(quote([
'--detoxURLBlacklistRegex',
`("^http://192.168.1.253:19001/onchange$")`
])).toBe(`--detoxURLBlacklistRegex '("^http://192.168.1.253:19001/onchange$")'`);
});
});

describe('.parse(str)', () => {
it('should parse command line calls', () => {
expect(parse('-w 3')).toEqual(['-w', '3']);
});

it('should parse command line calls with globs', () => {
expect(parse('--include **/*.test.js')).toEqual(['--include', '**/*.test.js']);
});

it('should not be able to parse operators', () => {
expect(parse('dog || cat')).toEqual(['dog', 'cat']);
});
});
});

0 comments on commit 95ee888

Please sign in to comment.