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

Error in Pathname#cleanpath #2347

Open
n-nishizawa opened this issue Dec 25, 2014 · 1 comment
Open

Error in Pathname#cleanpath #2347

n-nishizawa opened this issue Dec 25, 2014 · 1 comment

Comments

@n-nishizawa
Copy link

I'm using jruby 1.7.17 on windows 7.

$ jruby -v
jruby 1.7.17 (1.9.3p392) 2014-12-09 fafd1a7 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 +jit [Windows 7-amd64]

I ran this code.
And I got a error about encoding in Pathname#cleanpath with multi-byte(utf-8) string.

# coding: utf-8
require 'pathname'

str = './ディレクトリ0'

path = Pathname.new(str)
abs  = path.expand_path
abs.cleanpath
jruby -J-Dfile.encoding=utf-8 test_jp.rb
Encoding::CompatibilityError: incompatible character encodings: Windows-31J and UTF-8
                rindex at org/jruby/RubyString.java:3423
         chop_basename at C:/jruby-1.7.17/lib/ruby/1.9/pathname.rb:48
  cleanpath_aggressive at C:/jruby-1.7.17/lib/ruby/1.9/pathname.rb:101
             cleanpath at C:/jruby-1.7.17/lib/ruby/1.9/pathname.rb:89
                (root) at test_jp.rb:8

I think it's due to changing encoding in Path#expand_path.
Path#expand_path changes encoding on windows.
I tested the code below.

# coding: utf-8
require 'pathname'

str = './ディレクトリ0'

path = Pathname.new(str)
p path.to_s.encoding

abs = path.expand_path
p abs.to_s.encoding

And I got this result.

$ jruby -J-Dfile.encoding=utf-8 test_jp.rb
#<Encoding:UTF-8>
#<Encoding:Windows-31J>

Is it expected behavior?

@n-nishizawa
Copy link
Author

I think it's related with this line.
In the line, the encoding is forced into default external.
But in other similar methods(e.g. File.absolute_path), encoding is not forced to be changed.

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

No branches or pull requests

1 participant