Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: launch args with multiple values inside quotes #29077

Merged
merged 16 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _Released 2/27/2024 (PENDING)_

- Fixed an issue where `.click()` commands on children of disabled elements would still produce "click" events -- even without `{ force: true }`. Fixes [#28788](https://github.com/cypress-io/cypress/issues/28788).
- Changed RequestBody type to allow for boolean and null literals to be passed as body values. [#28789](https://github.com/cypress-io/cypress/issues/28789)
- Fixed launch args with multiple values inside quotes. Fixes [#27454](https://github.com/cypress-io/cypress/issues/27454).

**Dependency Updates:**

Expand Down
20 changes: 15 additions & 5 deletions packages/server/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,29 @@ try {
}

if (process.env.ELECTRON_EXTRA_LAUNCH_ARGS) {
const electronLaunchArguments = process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(' ')
const regex = /(?:[^\s"']+|"[^"]*"|'[^']*')+/g
erwin-huang marked this conversation as resolved.
Show resolved Hide resolved
const electronLaunchArguments = process.env.ELECTRON_EXTRA_LAUNCH_ARGS.match(regex) || []

electronLaunchArguments.forEach((arg) => {
// arg can be just key --disable-http-cache
// or key value --remote-debugging-port=8315
// https://github.com/cypress-io/cypress/issues/7994
const [key, value] = arg.split('=')
// or key value with another value --foo=--bar=4196
// or key value with another multiple value --foo='--bar=4196 --baz=quux'
const [key, ...value] = arg.split('=')

// because this is an environment variable, everything is a string
// thus we don't have to worry about casting
// --foo=false for example will be "--foo", "false"
if (value) {
app.commandLine.appendSwitch(key, value)
if (value.length) {
let joinedValues = value.join('=')

if (joinedValues.startsWith(`'`) && joinedValues.endsWith(`'`)) {
joinedValues = joinedValues.slice(1, -1)
} else if (joinedValues.startsWith('"') && joinedValues.endsWith('"')) {
joinedValues = joinedValues.slice(1, -1)
}
erwin-huang marked this conversation as resolved.
Show resolved Hide resolved

app.commandLine.appendSwitch(key, joinedValues)
} else {
app.commandLine.appendSwitch(key)
}
Expand Down
14 changes: 14 additions & 0 deletions packages/server/test/unit/environment_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ describe('lib/environment', () => {
expect(app.commandLine.appendSwitch).to.have.been.calledWith('--quux', 'false')
})

it('sets launch args with multiple values inside quotes', () => {
restore = mockedEnv({
ELECTRON_EXTRA_LAUNCH_ARGS: `--foo --ipsum=0 --bar=--baz=quux --lorem='--ipsum=dolor --sit=amet'`,
})

sinon.stub(app.commandLine, 'appendSwitch')
require(`../../lib/environment`)

expect(app.commandLine.appendSwitch).to.have.been.calledWith('--foo')
expect(app.commandLine.appendSwitch).to.have.been.calledWith('--ipsum', '0')
expect(app.commandLine.appendSwitch).to.have.been.calledWith('--bar', '--baz=quux')
expect(app.commandLine.appendSwitch).to.have.been.calledWith('--lorem', '--ipsum=dolor --sit=amet')
})

return afterEach(() => {
if (restore) {
return restore()
Expand Down