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

Can't pass hash values containing exponential operators to --env command line option. #6891

Closed
tzolnai opened this issue Mar 31, 2020 · 6 comments · Fixed by #8051 · May be fixed by Omrisnyk/npm-lockfiles#145 or Omrisnyk/npm-lockfiles#164
Assignees
Labels
good first issue Good for newcomers pkg/server This is due to an issue in the packages/server directory type: bug

Comments

@tzolnai
Copy link

tzolnai commented Mar 31, 2020

Current behavior:

We use --env variable to pass some environment variables to cypress, when it's running both in headless and headed mode.

One of the parameters is a hash (mix of numbers and characters). Surprisingly some specific hash values make cypress to fail reading this value from the command line (e.g. 769e98018). The corresponding environment variable is not set and the Cypress.env() function returns with null.

Desired behavior:

It should not be a problem to read a hash from the command line and put into an environment variable.

Test code to reproduce

A simplified command line call:

node_modules/cypress/bin/cypress open --env WSD_VERSION_HASH=769e98018

Test code showing the issue:

describe('Hash test.', function() {
    it('Test 1.', function() {
        expect(Cypress.env('WSD_VERSION_HASH')).to.equal('769e98018');
    });
});

This test fails with: 'expected null to equal 769e98018'

If I remove the 'e' character for example, then the value is read correctly.

Versions

Cypress 4.1.0
OpenSUSE 15.1 and Ubuntu 18.04

@CypressCecelia
Copy link
Contributor

I was able to confirm this behavior running locally on 4.1 and 4.3. Passing a string OR a number is fine, but a hash comes through as null.

@CypressCecelia CypressCecelia added cli stage: needs investigating Someone from Cypress needs to look at this type: bug labels Mar 31, 2020
@jennifer-shehane
Copy link
Member

Logged in plugins file configuration, the value is showing as null:

Logged in Settings - Configuration panel, the value is showing as Infinity 😅

Basically this value is being converted to a Number - due to the e, if you change the value to say '769d98018' - with a d, it is now read correctly as a string.

For example, lodash considers this a number.

Screen Shot 2020-04-01 at 2 04 30 PM

The transformation from the actual value to a Number (specifically Infinity) happens through this method:

https://github.com/cypress-io/cypress/blob/test-retries/packages/server/lib/util/args.js#L234

You can see if you log the value before and after that function that it's transformed to this value.

Screen Shot 2020-04-01 at 2 13 48 PM

The root culprit is actually this call here where it's calling JSON.parse('769e98018')

https://github.com/cypress-io/cypress/blob/test-retries/packages/server/lib/util/args.js#L85:L85

Screen Shot 2020-04-01 at 2 47 40 PM

It seems like the code has always been this way - I traced this code being here at least 2 years, so this is likely a very rare edge case.

@jennifer-shehane
Copy link
Member

I'm not really sure that I'll have time to address this, but the thought on how to handle this was to do a regex check for exponential operators and transform them to a string.

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: needs investigating Someone from Cypress needs to look at this labels Apr 9, 2020
@jennifer-shehane jennifer-shehane added good first issue Good for newcomers pkg/server This is due to an issue in the packages/server directory and removed cli labels Apr 9, 2020
@nimish-gupta
Copy link

Hey @jennifer-shehane, I can start working on this issue.

For this, I can check for infinity (Both negative and positive) after the value is parsed

@jennifer-shehane jennifer-shehane changed the title Can't pass some specific hash values to --env command line option. Can't pass hash values containing exponential operators to --env command line option. May 19, 2020
@jennifer-shehane
Copy link
Member

The code for this is done in cypress-io/cypress#8051, but has yet to be released.

We'll update this issue and reference the changelog when it's released.

@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: ready for work The issue is reproducible and in scope labels Aug 3, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 3, 2020

Released in 4.12.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.12.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/server This is due to an issue in the packages/server directory type: bug
Projects
None yet
4 participants