Skip to content

Commit

Permalink
fix: launch args with multiple values inside quotes (#29077)
Browse files Browse the repository at this point in the history
* fix: launch args with multiple values inside quotes

* chore: update change log

* chore: update changelog issue link

* chore: update  changelog prefix

* chore: update change log link

* fix: lint issues

* fix: lint issue

* Update packages/server/lib/environment.js

Co-authored-by: Bill Glesias <[email protected]>

* Update environment.js

* Update cli/CHANGELOG.md

Co-authored-by: Bill Glesias <[email protected]>

* fix: lint issues

---------

Co-authored-by: Bill Glesias <[email protected]>
Co-authored-by: Jennifer Shehane <[email protected]>
  • Loading branch information
3 people authored Apr 10, 2024
1 parent 1114ff4 commit 5251d2b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ _Released 4/16/2024 (PENDING)_

- Updated the Chrome flags to not show the "Enhanced Ad Privacy" dialog. Addresses [#29199](https://github.com/cypress-io/cypress/issues/29199).

**Bugfixes:**

- Fixed and issue where cypress launch arguments were not being escaped correctly with multiple values inside quotes. Fixes [#27454](https://github.com/cypress-io/cypress/issues/27454).


## 13.7.2

_Released 4/2/2024_
Expand Down
24 changes: 19 additions & 5 deletions packages/server/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,33 @@ try {
}

if (process.env.ELECTRON_EXTRA_LAUNCH_ARGS) {
const electronLaunchArguments = process.env.ELECTRON_EXTRA_LAUNCH_ARGS.split(' ')
// regex will be used to convert ELECTRON_EXTRA_LAUNCH_ARGS into an array, for example
// input: 'foo --ipsum=0 --bar=--baz=quux --lorem="--ipsum=dolor --sit=amet"'
// output: ['foo', '--ipsum=0', '--bar=--baz=quux', '--lorem="--ipsum=dolor --sit=amet"']
const regex = /(?:[^\s"']+|"[^"]*"|'[^']*')+/g
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('=')

// check if the arg is wrapped in " or ' (unicode)
const isWrappedInQuotes = !!['\u0022', '\u0027'].find(((charAsUnicode) => joinedValues.startsWith(charAsUnicode) && joinedValues.endsWith(charAsUnicode)))

if (isWrappedInQuotes) {
joinedValues = joinedValues.slice(1, -1)
}

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

4 comments on commit 5251d2b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5251d2b Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/linux-x64/develop-5251d2bb367ebb24d700d64766d0f5f2b11ea879/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5251d2b Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/linux-arm64/develop-5251d2bb367ebb24d700d64766d0f5f2b11ea879/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5251d2b Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/darwin-x64/develop-5251d2bb367ebb24d700d64766d0f5f2b11ea879/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5251d2b Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/darwin-arm64/develop-5251d2bb367ebb24d700d64766d0f5f2b11ea879/cypress.tgz

Please sign in to comment.