Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

fix(args): make args conversion stateless #85

Merged
merged 3 commits into from
Mar 14, 2017

Conversation

hgwood
Copy link
Collaborator

@hgwood hgwood commented Mar 14, 2017

Hello.

I was starting to make a contribution to cross-env and found this test. It looks like it is buggy. isWindowsMock is set to true, but the test expects $test not to be converted. And it passes! 😮

I looked into it and discovered this interesting fact about RegExp.prototype.exec: it's not stateless when used with the g flag! That's what is making the test pass.

So I added this test:

expect(commandConvert('$test')).toBe(commandConvert('$test'))

It does fail on master. To fix the problem, I have removed the g flag from the regexps in command.js. It is not useful anyway because exec is only called once.

Thanks for making cross-env, and for your consideration.

@codecov-io
Copy link

codecov-io commented Mar 14, 2017

Codecov Report

Merging #85 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master    #85   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines          34     34           
=====================================
  Hits           34     34
Impacted Files Coverage Δ
src/command.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 920451d...e94d08d. Read the comment docs.

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thank you for contributing this! Could you add yourself to the contributors table?

test(`converts windows-style env variable usage for linux`, () => {
isWindowsMock.__mock.returnValue = false
expect(commandConvert('%test%')).toBe('$test')
})

test(`leaves variable unchanged when using correct operating system`, () => {
isWindowsMock.__mock.returnValue = true
isWindowsMock.__mock.returnValue = false
Copy link
Owner

Choose a reason for hiding this comment

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

Thank you!


test(`is stateless`, () => {
// this test prevents falling into regexp traps like this:
// http://bit.ly/1zWb3tn
Copy link
Owner

Choose a reason for hiding this comment

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

Could you use the full URL instead? http://stackoverflow.com/a/1520853/971592

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@hgwood hgwood force-pushed the fix/stateless-command-convert branch from d09bb9d to e94d08d Compare March 14, 2017 16:09
@hgwood
Copy link
Collaborator Author

hgwood commented Mar 14, 2017

All done.

@hgwood hgwood changed the title fix: command conversion is not stateless fix(args): make args conversion stateless Mar 14, 2017
Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks!

@kentcdodds kentcdodds merged commit c1a9ed0 into kentcdodds:master Mar 14, 2017
@hgwood hgwood deleted the fix/stateless-command-convert branch March 14, 2017 16:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants