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

support escaped spaces in cli options #1774

Merged
merged 1 commit into from Jul 4, 2015
Merged

Conversation

adamgruber
Copy link
Contributor

The current parsing of options does not allow spaces within an option so this fixes that. This is particularly useful in the case of reporter options where a custom reporter may want to accept a string option that contains a space.

See adamgruber/mochawesome#20 for an example.

This patch would require any spaces to be escaped like --option option\ with\ spaces

@boneskull
Copy link
Member

I'm unclear why you can't just use double-quotes? Anyway, this looks ok to me.

@@ -22,9 +22,10 @@ function getOptions() {
try {
var opts = fs.readFileSync(optsPath, 'utf8')
.trim()
.replace(/\\\s+/, '%20')

Choose a reason for hiding this comment

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

  • The + would turn an escaped space followed by one or multiple unescaped spaces into a single '%20'.
  • The lack of a //g flag would make this regex only transform the first escaped whitespace and leave all others

E.g.:

"foo bar\\      \\ baz\\ boo".replace(/\\\s+/, '%20')
"foo bar%20\ baz\ boo"

@jbnicolai
Copy link

I'm unclear why you can't just use double-quotes?

I agree, I would always go for quoting as well. On the other hand, supporting escaped whitespaces is pretty standard as well, so why not ;)

Anyway, this looks ok to me.

It looks pretty broken to me 😛

@@ -22,9 +22,10 @@ function getOptions() {
try {
var opts = fs.readFileSync(optsPath, 'utf8')
.trim()

Choose a reason for hiding this comment

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

If the string ends with "\\ " trim will remove the trailing space. Edge case, I admit, but these two lines should be swapped.

@adamgruber
Copy link
Contributor Author

And this is why I shouldn't code late at night. 😜 Thanks for the feedback, I'll fix it.

@adamgruber adamgruber force-pushed the master branch 2 times, most recently from 0891077 to d8873c7 Compare July 4, 2015 12:48
@adamgruber
Copy link
Contributor Author

Made the changes and cleaned up the history.

@jbnicolai
Copy link

👍 thanks!

jbnicolai pushed a commit that referenced this pull request Jul 4, 2015
support escaped spaces in cli options
@jbnicolai jbnicolai merged commit c27110b into mochajs:master Jul 4, 2015
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.

None yet

3 participants