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

Illformed requirement when using powershell #1962

Closed
djberg96 opened this issue Jun 26, 2017 · 18 comments
Closed

Illformed requirement when using powershell #1962

djberg96 opened this issue Jun 26, 2017 · 18 comments

Comments

@djberg96
Copy link
Contributor

djberg96 commented Jun 26, 2017

ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]
Windows 10
Powershell 5.1

I'm getting a curious error when I try to use the --conservative option:

PS C:\Users\djber> gem install bundler -v '>=1.11.1' --conservative

ERROR:  While executing gem ... (Gem::Requirement::BadRequirementError)
   Illformed requirement ["--conservative"]

Curiously, I also see this when using the command shell if it's run via bundler, but not if I run it directly on the command line.

Back to powershell, I'm actually getting an error even without the --conservative option:

PS C:\Users\djber> gem install bundler -v ">=1.11.1"

ERROR:  While executing gem ... (OptionParser::MissingArgument)
    missing argument: -v
PS C:\Users\djber> gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.12
  - RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x64-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby23-x64/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: C:/Users/djber/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: C:/Ruby23-x64/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby23-x64/bin
  - SPEC CACHE DIRECTORY: C:/Users/djber/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:
    - ruby
    - x64-mingw32
  - GEM PATHS:
     - C:/Ruby23-x64/lib/ruby/gems/2.3.0
     - C:/Users/djber/.gem/ruby/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org"]
  - REMOTE SOURCES:
     - https://rubygems.org
  - SHELL PATH:
     - C:\Windows\system32
     - C:\Windows
     - C:\Windows\System32\Wbem
     - C:\Windows\System32\WindowsPowerShell\v1.0\
     - C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
     - C:\Windows\system32\config\systemprofile\.dnx\bin
     - C:\Program Files\Microsoft DNX\Dnvm\
     - C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
     - C:\Program Files\Git\cmd
     - C:\ProgramData\chocolatey\bin
     - C:\Program Files\Java\jdk1.8.0_102\bin
     - C:\Program Files (x86)\vim\vim74
     - C:\Program Files\Java\jdk1.8.0_112\bin
     - C:\Program Files (x86)\Skype\Phone\
     - C:\Program Files (x86)\vim\vim80
     - C:\Program Files (x86)\Heimdal\bin\
     - C:\Program Files\Heimdal\bin\
     - C:\Ruby23-x64\bin
     - C:\Users\djber\AppData\Local\Microsoft\WindowsApps
     -
     - C:\Program Files (x86)\Microsoft VS Code\bin
@segiddins
Copy link
Member

Does powershell handle quotes differently than the POSIX shell? What does this output? ruby -e "p(ARGV)" -- gem install bundler -v '>=1.11.1' --conservative

@djberg96
Copy link
Contributor Author

@segiddins The output using Powershell is:

["gem", "install", "bundler", "-v", ">=1.11.1", "--conservative"]

On the command prompt, I got no output. Strange.

@segiddins
Copy link
Member

No clue then, my best guess is that quoted args are handled differently (but I've never used powershell myself, so I can't say for certain)

@djberg96
Copy link
Contributor Author

@segiddins Ah, I think the quotes need to be preserved explicitly:

PS C:\Users\djber> gem install bundler -v '">=1.11.1"'
Successfully installed bundler-1.15.1
Parsing documentation for bundler-1.15.1
Done installing documentation for bundler after 7 seconds
1 gem installed
# Subsequently no error when I ran this:
PS C:\Users\djber> gem install bundler -v '">=1.11.1"' --conservative

Is this something we could handle on the backend? Or is it just a gotcha for powershell users? Because it needs to be handled by bundler somehow.

@segiddins
Copy link
Member

I don't need the double quoting under zsh, so my guess is this is a peculiarity with PowerShell?

@djberg96
Copy link
Contributor Author

djberg96 commented Jun 27, 2017

@segiddins I think without the quotes it's trying to evaluate an expression instead of accepting the string literal. I'll have to dig into the command line parser to be sure, though.

@duckinator
Copy link
Member

@djberg96 can you still reproduce this error?

If so, can you try gem install bundler -v '>=1.11.1' — I'm wondering if perhaps PowerShell treats single- and double-quoted arguments differently in a way that would cause this.

@djberg96
Copy link
Contributor Author

@duckinator will have to fire up a Windows VM to test, as I'm not really using Windows any more.

@MSP-Greg
Copy link
Contributor

@djberg96 @duckinator

Have to look at it later, but running the command in a command window seems to work (there is no output), but the same command in a PowerShell window does not.

I was using:

gem install bundler -v ">=1.11.1" --conservative
-- and --
gem install bundler --conservative -v ">=1.11.1"

A solution seems to be using (double) quotes, and 'backticking' them. As below:

gem install bundler -v `">=1.11.1`" --conservative
-- and --
gem install bundler --conservative -v `">=1.11.1`"

A backtick is the Powershell escaping character, like \ in Ruby. I've needed the backticks in PowerShell scripts running ruby CLI where quotes were needed...

@djberg96
Copy link
Contributor Author

@MSP-Greg Maybe we could handle it on the backend somehow then? While powershell users can get around it with extra quotes or backticks, it would be nicer and deals with the Bundler issue.

@bronzdoc
Copy link
Member

@djberg96 is this still an issue for you?

@djberg96
Copy link
Contributor Author

@bronzdoc Still happening as of rubygems 2.7.6, yes.

@djberg96
Copy link
Contributor Author

djberg96 commented Dec 31, 2018

@bronzdoc could we use the shellwords library perhaps? If we need to check for powershell explicitly, this was all I could find atm:

(dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell

That will return "Powershell" if powershell, or "CMD" if the old cmd shell.

@MSP-Greg
Copy link
Contributor

@djberg96

I think this issue is baked into windows, there is no fix for RG. Also, the 'greater-than' symbol is the issue, as without a backtick, it's considered a pipe character...

Create a one line *.cmd file @echo %*.

PS > ./ps_cli.cmd install did_you_mean -v `">=1.11.1`" --user-install
ARGS - install did_you_mean -v ">=1.11.1" --user-install

PS > ./ps_cli.cmd install did_you_mean -v ">=1.11.1" --user-install
< no output >

Running the second example, you'll also have a file created named 1.11.1 with the echo output in it...

@MSP-Greg
Copy link
Contributor

@djberg96

Forgot about something, it's called the 'stop-parsing symbol' --%

PS > ./ps_cli.cmd --% install did_you_mean -v ">=1.11.1" --user-install
ARGS - install did_you_mean -v ">=1.11.1" --user-install

Unfortunately, when used from a cmd prompt, it's interpreted as a argument...

@bronzdoc
Copy link
Member

A patch fixing this is appreciated, unfortunately i don't have a windows machine to test and debug.

@bronzdoc
Copy link
Member

@djberg96 is this still an issue for you?

@djberg96
Copy link
Contributor Author

djberg96 commented Apr 23, 2019

@bronzdoc Not for me personally, no, though it's still an issue in general, mainly for bundler.

I'll close it for now since it doesn't seem to be pressing. It can always be reopened later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants