From: "sophiathedev (Nguyen Thang) via ruby-core" Date: 2026-07-20T13:02:44+00:00 Subject: [ruby-core:126125] [Ruby Bug#22194] File.realpath and File.realdirpath handle differently path encoding incompatible with a filesystem's one Issue #22194 has been updated by sophiathedev (Nguyen Thang). I've submitted a PR to fix this issue here: https://github.com/ruby/ruby/pull/17981 Thank you @andrykonchin for the bug report and the helpful notes! ���� Any feedback on the PR is highly appreciated. ---------------------------------------- Bug #22194: File.realpath and File.realdirpath handle differently path encoding incompatible with a filesystem's one https://bugs.ruby-lang.org/issues/22194#change-118129 * Author: andrykonchin (Andrew Konchin) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- Both `realpath` and `realdirpath` methods accept a `path` parameter and try to return result in the `path`'s encoding. `realpath`: ```ruby File.realpath(".rubocop.yml").encoding # => # File.realpath(".rubocop.yml".encode("US-ASCII")).encoding # => # ``` `realdirpath`: ```ruby File.realdirpath("src").encoding # => # File.realdirpath("src".encode("US-ASCII")).encoding # => # ``` But it's possible that `path`'s encoding isn't compatible with the filesystem's one (that's is common to be UTF-8 on Linux and macOS), that's converting from the filesystem's encoding to `path`'s encoding fails. In this case `realpath` and `realdirpath` behaves differently - `realpath` just "forces" encoding to `path`'s one (and as fallback to filesystem's and then to binary if a string becomes broken) and `realdirpath` just skips this encoding and returns a string as is in the filesystem's encoding. `realpath`: ```ruby File.realpath(".".encode(Encoding::ISO_8859_1), "test_dir_����").encoding # => # ``` `realdirpath`: ```ruby File.realdirpath(".".encode(Encoding::ISO_8859_1), "test_dir_����").encoding # => # ``` It makes sense for the methods to handle this edge case consistently. -- 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/