ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:118957] [Ruby master Bug#20699] On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well
@ 2024-08-26  6:59 flatland001 (Hayato Arai) via ruby-core
  2024-08-28 12:08 ` [ruby-core:118975] " nobu (Nobuyoshi Nakada) via ruby-core
  0 siblings, 1 reply; 2+ messages in thread
From: flatland001 (Hayato Arai) via ruby-core @ 2024-08-26  6:59 UTC (permalink / raw)
  To: ruby-core; +Cc: flatland001 (Hayato Arai)

Issue #20699 has been reported by flatland001 (Hayato Arai).

----------------------------------------
Bug #20699: On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well
https://bugs.ruby-lang.org/issues/20699

* Author: flatland001 (Hayato Arai)
* Status: Open
* ruby -v: ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x64-mingw-ucrt]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
In paths containing Japanese characters, such as:
C:\テスト_test\test.rb

Code:
``` ruby
#     this code -> C:\テスト_test\test.rb
# external file -> C:\テスト_test\lib\foo.rb
p __dir__
p __dir__.encoding
p File.dirname(File.expand_path(__FILE__))
p File.dirname(File.expand_path(__FILE__)).encoding
print "__dir__ == File.dirname(File.expand_path(__FILE__)): "
p __dir__ == File.dirname(File.expand_path(__FILE__))

begin
  require_relative "lib/foo"
  puts "foo.rb loaded"
rescue LoadError
  puts "LoadError: #{$!}"
end
```

Results:
```
"C:/?e?X?g_test"
#<Encoding:Windows-31J>
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
__dir__ == File.dirname(File.expand_path(__FILE__)): false
LoadError: cannot load such file -- C:/?e?X?g_test/lib/foo
```

However, in ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x64-mingw-ucrt], the same code produces the following expected results:
```
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
__dir__ == File.dirname(File.expand_path(__FILE__)): true
foo.rb loaded
```

Is this behavior expected, or could this be a bug in the Ruby interpreter on Windows? If this is my misunderstanding or a known issue, I apologize. Thank you for your consideration.

Environment Information:
- OS: Windows 11 Pro 23H2 (OS build 22631.4037)
- Installed via: RubyInstaller
- Shell: Command Prompt
- File System: NTFS
- System Locale: Japanese (Japan), Language: Japanese




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:118975] [Ruby master Bug#20699] On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well
  2024-08-26  6:59 [ruby-core:118957] [Ruby master Bug#20699] On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well flatland001 (Hayato Arai) via ruby-core
@ 2024-08-28 12:08 ` nobu (Nobuyoshi Nakada) via ruby-core
  0 siblings, 0 replies; 2+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-08-28 12:08 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20699 has been updated by nobu (Nobuyoshi Nakada).


This may be fixed already on the master?

----------------------------------------
Bug #20699: On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well
https://bugs.ruby-lang.org/issues/20699#change-109548

* Author: flatland001 (Hayato Arai)
* Status: Open
* ruby -v: ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x64-mingw-ucrt]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
In paths containing Japanese characters, such as:
C:\テスト_test\test.rb

Code:
``` ruby
#     this code -> C:\テスト_test\test.rb
# external file -> C:\テスト_test\lib\foo.rb
p __dir__
p __dir__.encoding
p File.dirname(File.expand_path(__FILE__))
p File.dirname(File.expand_path(__FILE__)).encoding
print "__dir__ == File.dirname(File.expand_path(__FILE__)): "
p __dir__ == File.dirname(File.expand_path(__FILE__))

begin
  require_relative "lib/foo"
  puts "foo.rb loaded"
rescue LoadError
  puts "LoadError: #{$!}"
end
```

Results:
```
"C:/?e?X?g_test"
#<Encoding:Windows-31J>
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
__dir__ == File.dirname(File.expand_path(__FILE__)): false
LoadError: cannot load such file -- C:/?e?X?g_test/lib/foo
```

However, in ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x64-mingw-ucrt], the same code produces the following expected results:
```
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
"C:/\x{8365}\x{8358}\x{8367}_test"
#<Encoding:Windows-31J>
__dir__ == File.dirname(File.expand_path(__FILE__)): true
foo.rb loaded
```

Is this behavior expected, or could this be a bug in the Ruby interpreter on Windows? If this is my misunderstanding or a known issue, I apologize. Thank you for your consideration.

Environment Information:
- OS: Windows 11 Pro 23H2 (OS build 22631.4037)
- Installed via: RubyInstaller
- Shell: Command Prompt
- File System: NTFS
- System Locale: Japanese (Japan), Language: Japanese




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-28 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-26  6:59 [ruby-core:118957] [Ruby master Bug#20699] On Windows, the `__dir__` keyword is garbled in paths containing Japanese characters, and `require_relative` fails as well flatland001 (Hayato Arai) via ruby-core
2024-08-28 12:08 ` [ruby-core:118975] " nobu (Nobuyoshi Nakada) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).