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

Ensure empty string is added into argv._ #140

Merged
merged 2 commits into from
Nov 19, 2018
Merged

Ensure empty string is added into argv._ #140

merged 2 commits into from
Nov 19, 2018

Conversation

jacksdrobinson
Copy link
Contributor

@jacksdrobinson jacksdrobinson commented Oct 8, 2018

A string such as "hello '' world" would parse into ["hello", undefined, "world"].
This would add a catch for that, ensuring that an empty string is pushed
instead, and adds associated tests.

Prior to this commit, a string such as "hello '' world" would parse into
["hello", undefined, "world"]. This adds a catch for that, ensuring that
an empty string is pushed instead, and adds associated tests.
@@ -17,6 +17,7 @@ module.exports = function (argString) {
// split on spaces unless we're in quotes.
if (c === ' ' && !opening) {
if (!(prevC === ' ')) {
if (!args[i]) args[i] = ''
Copy link
Member

Choose a reason for hiding this comment

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

👋 for this fix, I think it would make sense to move the logic down to the check for the closing quote. So something like:

    if (c === opening) {
      if (!args[i]) args[i] = ''
      opening = null
      continue
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see how that would make sense - placing it at the point of detecting the closing quotes. Both ways pass the tests, so I'll commit the change.

The reason I put it where I did was to ensure that we can't possibly increment i before we've checked for a missing argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committed :)

@bcoe
Copy link
Member

bcoe commented Nov 8, 2018

@jacksdrobinson thank you for the contribution, left a comment.

This issue concerns when arguments are undefined due to empty quoted
strings. Therefore, it makes sense to place the check for an undefined
argument into the block which detects the closing quotes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants