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

Cypress fails to parse environment variables with empty values #3742

Closed
Ameobea opened this issue Mar 18, 2019 · 2 comments

Comments

2 participants
@Ameobea
Copy link
Contributor

commented Mar 18, 2019

Current behavior:

Cypress fails to parse command line environment variables when environment variables with empty values are supplied.

Desired behavior:

Should default to setting the values to undefined

Steps to reproduce: (app code and test code)

Run a command like cypress run --env="USERNAME=,PASSWORD="

Versions

3.2.0 and earlier


Stack trace:

A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: Cannot read property 'split' of undefined
    at pipesToCommas (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/util/args.js:95:13)
    at JSONOrCoerce (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/util/args.js:115:9)
    at /root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:13402:38
    at /root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4911:15
    at baseForOwn (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:2996:24)
    at Function.mapValues (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:13401:7)
    at /root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4374:28
    at arrayReduce (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:683:21)
    at baseWrapperValue (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:4373:14)
    at LodashWrapper.wrapperValue (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/node_modules/lodash/lodash.js:9052:14)
    at sanitizeAndConvertNestedArgs (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/util/args.js:150:4)
    at Object.toObject (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/util/args.js:225:21)
    at Object.start (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/lib/cypress.js:70:40)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/index.js:21:43)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/app/packages/server/index.js:23:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/app/index.js:2:1)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/app/index.js:3:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/electron.asar/browser/init.js:171:8)
    at Object.<anonymous> (/root/.cache/Cypress/3.2.0/Cypress/resources/electron.asar/browser/init.js:173:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:167:16)
    at bootstrap_node.js:589:3
@cypress-bot

This comment has been minimized.

Copy link

commented Mar 20, 2019

The code for this is done in cypress-io/cypress#3743, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

flotwig added a commit that referenced this issue Mar 20, 2019

Fix parsing environment variables with empty values (#3743)
Fixes #3742

 * When parsing `--env` arguments containing variables with empty values (a valid pattern), Cypress crashed due to trying to `.split()` on an `undefined`.  For example, `cypress run --env="USERNAME=,PASSWORD="` would crash the application.
 * This commit changes the regular expression used to parse environment variables to use a `.*` rather than a `.+`.  This will initialize environment variables that are supplied without values to an empty string.  Since empty strings are falsy in JavaScript, this should work fine with users defaulting to hardcoded values in the case that environment variables aren't supplied (the use case that I was trying to create when I encountered this bug)

Previous behavior:

```sh
"USERNAME=,PASSWORD=".split(',').map(pair => pair.split(/=(.+)/))
// [["USERNAME="], ["PASSWORD="]]
```

New behavior:

```sh
"USERNAME=,PASSWORD=".split(',').map(pair => pair.split(/=(.*)/))
// [["USERNAME=", "", ""], ["PASSWORD=", "", ""]]
```

<!--
Thanks for contributing!

Please explain what changes were made and also
reference any issues that were fixed with #[ISSUE]
-->

laurinenas added a commit to laurinenas/cypress that referenced this issue Apr 28, 2019

Fix parsing environment variables with empty values (cypress-io#3743)
Fixes cypress-io#3742

 * When parsing `--env` arguments containing variables with empty values (a valid pattern), Cypress crashed due to trying to `.split()` on an `undefined`.  For example, `cypress run --env="USERNAME=,PASSWORD="` would crash the application.
 * This commit changes the regular expression used to parse environment variables to use a `.*` rather than a `.+`.  This will initialize environment variables that are supplied without values to an empty string.  Since empty strings are falsy in JavaScript, this should work fine with users defaulting to hardcoded values in the case that environment variables aren't supplied (the use case that I was trying to create when I encountered this bug)

Previous behavior:

```sh
"USERNAME=,PASSWORD=".split(',').map(pair => pair.split(/=(.+)/))
// [["USERNAME="], ["PASSWORD="]]
```

New behavior:

```sh
"USERNAME=,PASSWORD=".split(',').map(pair => pair.split(/=(.*)/))
// [["USERNAME=", "", ""], ["PASSWORD=", "", ""]]
```

<!--
Thanks for contributing!

Please explain what changes were made and also
reference any issues that were fixed with #[ISSUE]
-->
@cypress-bot

This comment has been minimized.

Copy link

commented May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.