Selecting a ruby when PATH contains & cuts off some of PATH

Issue #70 closed
Michael Metz
created an issue

If PATH contains special characters (such as &) then evertything after the & is cutoff when you select a ruby

ex.

C:\Program Files (x86)\Ruby>uru ls
    193p551     : ruby 1.9.3p551 (2014-11-13) [i386-mingw32]
    215p273     : ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
 => system      : ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]

C:\Program Files (x86)\Ruby>uru 193
---> Now using ruby 1.9.3-p551 tagged as `193p551`
'MySQL' is not recognized as an internal or external command,
operable program or batch file.
'MySQL' is not recognized as an internal or external command,
operable program or batch file.

Before PATH:

C:\ProgramData\Oracle\Java\javapath;
...
;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1
.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\
Doctrine extensions for PHP\;C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64\bin;

After PATH:

"C:\Program Files (x86)\Ruby\Ruby193\bin;_U_;C:\ProgramData\Oracle\Java\javapath;
...
;C:\Program Files (x86)\MySQL\
MySQL Fabric 1.5.3 "

If you are using system calls to set the PATH, you can set it with SET "PATH=<yourAddedPath>;%PATH%"

put quotes around the entire "VAR=VAR" to not cause this error.

Comments (12)

  1. Jon repo owner
    • edited description

    It definitely looks like uru's PATH splitting and recombining code isn't correctly handling MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5 path component.

    Good catch. Uru should handle needlessly awkward PATHs like this one from Oracle.

    What version of uru are you running?

  2. Jon repo owner

    While I look into how best to handle this in uru, based upon the following quick test, I have a short-term "fix" that may work for you: manually edit your PATH and put double quotes around all components that contain &.

    # Win8.1 x64 system using Command Prompt shell
    
    C:\>echo %PATH%
    "C:\Apps\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5";C:\ProgramData\Oracle\Java\javapath;...
    
    C:\>uru ver
    uru v0.7.7 [windows/386 go1.4]
    
    C:\>uru ls
        1719        : jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) ...
        200p630-x32 : ruby 2.0.0p630 (2015-01-30 revision 49450) [i386-mingw32]
        215p291-x32 : ruby 2.1.5p291 (2015-02-09 revision 49548) [i386-mingw32]
        220p43-x32  : ruby 2.2.0p43 (2015-02-06 revision 49530) [i386-mingw32]
    
    C:\>uru 220
    ---> Now using ruby 2.2.0-p43 tagged as `220p43-x32`
    
    C:\>echo %PATH%
    C:\Apps\rubies\ruby-2.2\bin;_U_;"C:\Apps\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5";C:\ProgramData\Oracle\Java\javapath;...
    
    C:\>uru 21
    ---> Now using ruby 2.1.5-p291 tagged as `215p291-x32`
    
    C:\>echo %PATH%
    C:\Apps\rubies\ruby-2.1\bin;_U_;"C:\Apps\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5";C:\ProgramData\Oracle\Java\javapath;...
    
    C:\>uru nil
    ---> removing non-system ruby from current environment
    
    C:\>echo %PATH%
    "C:\Apps\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5";C:\ProgramData\Oracle\Java\javapath;...
    

    From your info, it appears you're running a Windows 64bit system and using a Command Prompt shell. If this is incorrect (e.g. - using PowerShell or Cygwin bash or ??), reply with details of your environment.

  3. Jon repo owner

    Try this v0.7.8.alpha test build and let me know how it works.

    Uru works its magic by having a shell specific wrapper script update PATH in the current shell. The trivial fix of double quoting this to SET "PATH=%s" should fix your issue. It also likely breaks systems already using double quotes for their PATH components.

    Before releasing, I want your help with:

    1. How did your PATH get set to include &? The MySQL Fabric installer or your manual edit?
    2. Show me the output (relevant to &) of set PATH from your Command Prompt shell.
    3. Confirm that your PATH var when viewed from the System Properties -> Advanced -> Environment Variables GUI does not contain double quotes around the & components
    4. Show me the relevant output of reg query HKCU\Environment /v Path and reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
  4. Michael Metz reporter

    Sorry I am on vacation right now, so I may little slow to respond. I will try your new build.

    Environment is Windows 8.1 x64. Using cmd.exe

    For your trivial set fix, is there any way you can double up the double quotes within PATH, then double quote SET "PATH=%s"? I have some hackish cmd code that does this, but it would be cleaner if you do it in a real scripting or programming language. See my comment on why you need to double the double quotes on my stack overflow comments. http://stackoverflow.com/questions/11893309/escape-double-quotes-inside-batchs-input-parameters/11893337#comment42569802_11893337

    1. The path got added from the MYSQL installer, when adding the utilities. http://dev.mysql.com/downloads/windows/installer/ or http://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-5.6.23.0.msi

    2. SET PATH (outputs): Path=C:\ProgramData\Oracle\Java\javapath; ;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1 .5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\ Doctrine extensions for PHP\;C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64\bin;

    3. No double quotes.

    4. (outputs):

    reg query HKCU\Environment /v Path
    
    HKEY_CURRENT_USER\Environment
        Path    REG_SZ    C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64
    \bin;
    ...
    
    
    reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path
    
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
        Path    REG_EXPAND_SZ    C:\ProgramData\Oracle\Java\javapath;
    ...
    ;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1
    .5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\
    Doctrine extensions for PHP\;C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64\bin;
    
  5. Jon repo owner

    Thanks for providing the details of your environment.

    For now, I want to quickly release a fix for your scenario as it's caused by the behavior of a well-known installer. While I've not decided how to best address escaping existing double quotes within PATH, I'll put an entry on the FAQ wiki page. Feel free to refine the upcoming entry if needed.

  6. Jon repo owner

    I don't know if or when you'll be able to confirm that v0.7.8.alpha works for you, but I think the fix will solve your original issue and is safe enough to move forward with a new release.

  7. Michael Metz reporter

    Sorry I got back from vacation a few days ago and was busy with some work.

    I tested the alpha and it works for any un-quoted paths (which is what the MySQL connector installer created).

    C:\Ruby\UnleashRuby>uru_rt admin install
    ---> Installing uru into C:\Ruby\UnleashRuby
    
    C:\Ruby\UnleashRuby>uru ls
        193p551     : ruby 1.9.3p551 (2014-11-13) [i386-mingw32]
     => system      : ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
    
    C:\Ruby\UnleashRuby>uru 193
    ---> Now using ruby 1.9.3-p551 tagged as `193p551`
    
    C:\Ruby\UnleashRuby>echo "%PATH%"
    "C:\Program Files (x86)\Ruby\Ruby193\bin;_U_;C:\ProgramData\Oracle\Java\javapath;
    ...
    ;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1
    .5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\
    Doctrine extensions for PHP\;C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64\bin;"
    
    C:\Ruby\UnleashRuby>uru sys
    ---> Now using ruby 2.1.5-p273 tagged as `system`
    
    C:\Ruby\UnleashRuby>echo "%PATH%"
    "C:\ProgramData\Oracle\Java\javapath;
    ...
    ;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1
    .5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\
    Doctrine extensions for PHP\;C:\Program Files (x86)\Ruby\UnleashRuby;C:\Ruby\Ruby21-x64\bin;"
    

    If you do end up double double-quoting "dir1;""dir2""" (escaping) within PATH, that will work with all special character cases; whether someone has double-quotes in their path or if someone does not. That being said, installers usually do not add double quotes to PATH. It sill may be a good feature to have to cover yours bases though.

    Thank you for your hard work and timely responses.

  8. Jon repo owner

    Fix PATH handling in bat wrapper. Closes #70

    The cmd.exe batch file wrapper used to dynamically change the shell's PATH envar broke in the presence of the '&' char when executing SET PATH. This quickfix quotes the SET call but may cause problems with PATHs that already contain quoted path components.

    → <<cset ee2f4a8df7c0>>

  9. Log in to comment