uru auto cannot find non-ASCII .ruby-version files

Issue #86 new
Kashif Iqbal Khan created an issue

I saw the similar bug reported. However I believe my case if different. I am on Windows 7 x64. Here is the powershell outputs:

#!

PS C:\Ruby\Uru> cat $env:USERPROFILE\.ruby-version
2.0.0p647
#!


PS C:\Ruby\Uru> uru auto
---> unable to find or process a `.ruby-version` file
#!


PS C:\Ruby\Uru> cat $env:USERPROFILE\.uru\rubies.json
{
  "Version": "1.0.0",
  "Rubies": {
    "2700685649": {
      "ID": "2.0.0-p647",
      "TagLabel": "200p647",
      "Exe": "ruby",
      "Home": "C:\\Ruby\\RubyInstalls\\Ruby200-x64\\bin",
      "GemHome": "",
      "Description": "ruby 2.0.0p647 (2015-08-18) [x64-mingw32]"
    }
  }
}

Comments (3)

  1. Jon repo owner

    Good catch, thank you for reporting.

    Uru currently does not appear to handle .ruby-version files that are not in ASCII. I'll look into this and look for a fix. The workaround is to delete your current $env:USERPROFILE\.ruby-version file and recreate it in ASCII format. You can force Powershell to generate an ASCII .ruby-version file by using echo 225p235 | out-file -encoding ascii .ruby-version

    At first I could not reproduce your error

    C:\Apps\HeidiSQL> cat $env:USERPROFILE\.ruby-version
    225p235
    
    C:\Apps\HeidiSQL> uru ls
        219p441-x32 : ruby 2.1.9p441 (2015-12-23 revision 53262) [i386-mingw32]
        225p235-x32 : ruby 2.2.5p235 (2015-12-23 revision 53258) [i386-mingw32]
        jruby       : jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit...
    
    C:\Apps\HeidiSQL> uru auto
    ---> now using ruby 2.2.5-p235 tagged as `225p235-x32`
    
    C:\Apps\HeidiSQL> uru ls
        219p441-x32 : ruby 2.1.9p441 (2015-12-23 revision 53262) [i386-mingw32]
     => 225p235-x32 : ruby 2.2.5p235 (2015-12-23 revision 53258) [i386-mingw32]
        jruby       : jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit...
    

    I then deleted my .ruby-version file and created a new one via PowerShell. I was then able to reproduce your error.

    C:\Users\Jon> echo 225p235 > .ruby-version
    
    C:\Apps\HeidiSQL> cat $env:USERPROFILE\.ruby-version
    225p235
    
    C:\Apps\HeidiSQL> uru ls
        219p441-x32 : ruby 2.1.9p441 (2015-12-23 revision 53262) [i386-mingw32]
        225p235-x32 : ruby 2.2.5p235 (2015-12-23 revision 53258) [i386-mingw32]
        jruby       : jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit...
    
    C:\Apps\HeidiSQL> uru auto
    ---> unable to find or process a `.ruby-version` file
    

    The problem was that Powershell created a non-ASCII version (UTF16) of .ruby-version as shown by this hex dump

    00000000: FFFE 3200 3200 3500 7000 3200 3300 3500  ..2.2.5.p.2.3.5.
    00000010: 0D00 0A00                                ....
    
  2. Jon repo owner

    I'm not happy with the current code for this one. For example, this code does a simple string conversion on the raw bytes read from .ruby-version, e.g. - string(bytes.ToLower(bytes.Trim(b, " \r\n"))), and directly uses the result to search against the tag labels (JSON persisted) of registered rubies.

    Since JSON can use unicode chars in strings, the current tag label fuzzy matching code likely falls down when one tags a ruby using non-ASCII unicode chars.

    The current matching code needs reviewed and revised. Until I get back to this one, the safest workaround appears to be to use ASCII for both tag labels and the contents of .ruby-version.

  3. Log in to comment