oneclick / rubyinstaller2

MSYS2 based RubyInstaller for Windows
https://rubyinstaller.org
BSD 3-Clause "New" or "Revised" License
644 stars 248 forks source link

Gem commands fail if Windows user have a white space when installed for all users #332

Closed HatsuMora closed 1 year ago

HatsuMora commented 1 year ago

I reported this issue first in https://github.com/rubygems/rubygems/issues/6288 and they recommended me to also create a issue here.

What problems are you experiencing?

After upgrading from rubygems (gem) from 3.3.3 to 3.4.4 I could not install any gem or run several gem-related commands. For example gem env.

ERROR: While executing gem ... (Gem::CommandLineError) Unknown environment option [Rincón]

or gem install rails: ERROR: While executing gem ... (URI::InvalidURIError) URI must be ascii only "Rinc\u00F3n".

I tried to investigate the issue myself and find out that there is value.split(" ") on C:\langs\Ruby32-x64\lib\ruby\3.2.0\rubygems\command.rb:79 that will split arguments by white space therefore my user name is being splitter and miss interpreted. This extra arg is set by lib\ruby\3.2.0\rubygems\defaults\operating_system.rb:11. Operating system is setting a default --install-dir and --bindir based on Gem.user_dir.

As a workaround for myself, I added wrapped both paths on ' in operating_system.rb and change the split to@extra_args = value.split(/\s+(?=([^']*"[^']*')*[^']*$)/) in command.rb (split by white spaces that are not between single quotes).

Steps to reproduce

  1. Create a windows user that contains a white space on the user path.
  2. Install Ruby+Devkit 3.2.0-1 (x64) from Ruby Installer.
  3. When asked, install for all users. (Requires elevation)
  4. run gem env or gem install rails

What's the output from ridk version?

ruby: path: C:/langs/Ruby32-x64 version: 3.2.0 platform: x64-mingw-ucrt ruby_installer: package_version: 3.2.0-1 git_commit: 5507d7c msys2: path: C:\langs\Ruby32-x64\msys64 cc: gcc (Rev7, Built by MSYS2 project) 12.2.0 sh: GNU bash, version 5.2.9(1)-release (x86_64-pc-msys) os: Microsoft Windows [Version 10.0.22621.1105]