-
Notifications
You must be signed in to change notification settings - Fork 256
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
Ruby require fails when the path has special characters #265
Ruby require fails when the path has special characters #265
Comments
I have run this script in that directory: p __dir__.encoding
p Dir.pwd.encoding
puts
p __ENCODING__
p ''.encoding
p Encoding.default_external
p Encoding.default_internal and the output is
This is Windows 10 running in Parallels Desktop. I suspect that just shows my ignorance wrt how file encoding works in Windows, and also what can a Ruby program assume when reading file/directory names. |
Thanks for posting this here @fxn - I opened the issue here so that we can get closer to finding the correct place to fix this :) since the issues is clearly to do with Ruby + Windows, and not Rails. This is what I get with codepage 65001 (UTF-8)
and with codepage 437
Can you please check your codepage by doing |
@mohits it says 437. |
If I execute
Almost! |
Hi @fxn - Yes, I think Unsurprisingly, my simple test works on JRuby, of course - it successfully requires the file. Also, your code matches the output for chcp 65001 when run with JRuby even on a console that is CP-437.
|
Today I could not reproduce, trying more carefully. The file system in my machine is in puts Encoding.find('filesystem')
p Dir.pwd.bytes[-1]
require_relative "bar" This works, and the output is
If you check the codes in @mohits Can you reproduce using these steps? Maybe the directory was created with UTF-8 bytes for a non-UTF-8 file system? |
However, This is interesting, because both @mohits what happens in your machine with |
hi @fxn - I am a bit confused now with the results I am seeing but I have progress to report (kind of..) [1] I created this path:
[2] I ran your code:
On my system, it shows both it as UTF-8. I did a
[3] I forced it to change to CP-437 again by doing
It read the character properly (as 52) but failed on the require_relative. [4] On the other hand, with
So, to summarise:
I found this online: http://zuga.net/articles/text-ascii-vs-cp-1252-vs-cp-437/ that compares the code pages side by side.
In this, CP-1252 has the 2 characters at 224 and 248 respectively. |
@mohits Which Ruby version is that? I discovered by testing related things in Zeitwerk that in Ruby 3.0 the file system encoding is assumed (unsure if the verb is correct) to be UTF-8. This issue in Redmine seems relevant. |
@fxn - my bad. I should have included the ruby version: 3.0.3. More information then:
Yes, the issue on Redmine does seem relevant and might explain the result we see for the character code and encoding... but it appears that |
What problems are you experiencing?
If the path has special characters in it and you try to run a Ruby script that does a relative_require on that path, it fails to load the file. It's almost certainly something to do with encoding on the Windows console.
It failed for me with:
Active code page: 437
andActive code page: 65001
This ticket is based on an issue on rails at rails/rails#29087
Steps to reproduce
Create a folder called
Test Ø
and in it have 2 files:1.rb
2.rb
You should see an error like this:
What's the output from
ridk version
?ruby:
path: C:/Ruby30-x64
version: 3.0.3
platform: x64-mingw32
ruby_installer:
package_version: 3.0.3-1
git_commit: 981867a
msys2:
path: C:\Ruby30-x64\msys64
cc: gcc (Rev2, Built by MSYS2 project) 11.2.0
sh: GNU bash, version 5.1.8(1)-release (x86_64-pc-msys)
os: Microsoft Windows [Version 10.0.19044.1586]
The text was updated successfully, but these errors were encountered: