-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Comments
The code for this is done in cypress-io/cypress#3743, but has yet to be released. |
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] -->
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] -->
Released in |
Just an update in case anyone is still seeing this issue. I had a similar issue happen even after upgrading to 3.3.2 version of Cypress. The issue I had looks something like this,
The space before |
In case it's useful for someone else, I was doing something pretty silly... The cypress folder is not at the root of the project so I wanted to launch it with an argument specifying that. Reading the doc, I found an argument So I was doing:
This flag's actually not for that at all. And I have to do instead:
The error I had with the first one was
So it took me about 20mn to figure out what was wrong 😅 |
@maxime1992 Understandable. We do have an issue to add a |
@maxime1992 @jennifer-shehane The correct way to load a different config: yarn run cypress open --config-file ./yourconfig.json |
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:
The text was updated successfully, but these errors were encountered: