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

Fix running commands on Windows (#387) #422

Merged
merged 2 commits into from
Jun 24, 2017
Merged

Conversation

dmitryfleytman
Copy link
Contributor

@dmitryfleytman dmitryfleytman commented Dec 22, 2016

Summary

This pull request fixes #387 and makes aruba functional on Windows

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Dmitry Fleytman added 2 commits December 22, 2016 14:51
Cross-platform and Windows specific code should avoid
use of UNIX specific PATH_SEPARATOR (colon) in favor
of portable constant File::PATH_SEPARATOR
ShellWords used by WindowsCommandString for command line parsing
is not tolerant to Windows path separator (backslash).
As a result WindowsCommandString.to_a returns wrong values
with path separator characters stripped out.

This patch temporary replaces path separators with placeholders
before feeding command line to ShellWords and then replaces those
placeholders back in ShellWords output.

While this is a hack rather than a clean solution, it
fixes WindowsCommandString.to_a without introducing code
or dependencies.

As far as authors can tell, it also covers all possible
scenarios and corner cases.
@dmitryfleytman
Copy link
Contributor Author

Hello,

Have you had a chance to look at this yet?

Thanks in advance,
Dmitry

@dmitryfleytman
Copy link
Contributor Author

Ping?

1 similar comment
@dmitryfleytman
Copy link
Contributor Author

Ping?

@thomthom
Copy link

thomthom commented May 3, 2017

I second this ping. This PR allowed me to run Aruba under Windows. It would be nice to be able to run a build from the main channel and not a custom patched version.

@dmitryfleytman
Copy link
Contributor Author

For now, I pushed gem aruba-win-fix with this PR applied.

Copy link
Member

@maxmeyer maxmeyer left a comment

Choose a reason for hiding this comment

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

Besides the #to_a your PR looks good to me.

@@ -16,7 +16,8 @@ def initialize(cmd)

# Convert to array
def to_a
Shellwords.split __getobj__
Shellwords.split( __getobj__.gsub('\\', 'ARUBA_TMP_PATHSEPARATOR') ).
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean, Shellwords does not support windows correctly?

Copy link
Contributor Author

@dmitryfleytman dmitryfleytman May 10, 2017

Choose a reason for hiding this comment

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

Yes, shellwords swallows Windows path separators:

irb(main):001:0> require 'shellwords'
=> true
irb(main):002:0> Shellwords.split('c:\\windows\\system32')
=> ["c:windowssystem32"]

The solution in this PR is not very elegant, but it looks safe in given context.

A few more interesting observations:

This does not work:

irb(main):003:0> Shellwords.split('c:\\windows\\system32'.gsub('\\', '\\\\'))
=> ["c:windowssystem32"]

While this does work:

irb(main):004:0> Shellwords.split('c:\\windows\\system32'.gsub('\\', '\\\\\\\\'))
=> ["c:\\windows\\system32"]

So it might be solution as well, however it looks too subtle...

Copy link
Member

@maxmeyer maxmeyer May 19, 2017

Choose a reason for hiding this comment

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

What about replacing \\ by / instead? Looks more obvious where the problem is. Or get rid of Shellwords.split for windows all together. Though I'm not sure, if this does not cause other problems.

__getobj__.split(/\s+/)

@maxmeyer
Copy link
Member

maxmeyer commented May 8, 2017

Sorry for the delay. I missed that PR.

@dmitryfleytman
Copy link
Contributor Author

@maxmeyer, no problem, thanks for looking at it.

@dmitryfleytman
Copy link
Contributor Author

Hi @maxmeyer , have you seen my comment regarding the proposed to_a implementation?

@maxmeyer
Copy link
Member

Sorry for the delay, what do you think about my proposal?

@dmitryfleytman
Copy link
Contributor Author

@maxmeyer, I would not recommend replacing \\ by / because / is widely used on Windows for command line switches, like copy /Y /N ....

Should I put a comment with explanations into the to_a instead?

@dmitryfleytman
Copy link
Contributor Author

@maxmeyer, have you seen my reply?

@maxmeyer maxmeyer merged commit 1c7e765 into cucumber:master Jun 24, 2017
@dmitryfleytman dmitryfleytman deleted the d-win-fix branch June 26, 2017 11:17
@dmitryfleytman
Copy link
Contributor Author

Thanks, @maxmeyer

Would you mind releasing a new version?

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.

Running commands on Windows is broken
3 participants