[ruby-core:120047] [Ruby master Bug#20920] When loading a file, __FILE__ gets relative paths expanded only when they start with "./"

Issue #20920 has been reported by deivid (David Rodríguez). ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920 * Author: deivid (David Rodríguez) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/

Issue #20920 has been updated by Dan0042 (Daniel DeLorme). It's interesting that this highlights the only case where `load` searches in a different path than `require` if path is absolute load/require absolute path --> __FILE__ is absolute elsif path starts with "." or ".." load/require relative to pwd --> __FILE__ is expanded to absolute else load/require relative to each $LOAD_PATH --> __FILE__ is expanded to absolute if above not found, load (but not require) relative to pwd --> __FILE__ is NOT expanded to absolute end ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920#change-110871 * Author: deivid (David Rodríguez) * Status: Open * ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/

Issue #20920 has been updated by vo.x (Vit Ondruch). This is very related to #16978 And all this started with introduction of `require_relative` and it is a mess since then. IMHO, the path expansion is evil. It prevents usage of symlinks, it is troublesome with modifications of `$LOAD_PATH`, etc. ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920#change-110872 * Author: deivid (David Rodríguez) * Status: Open * ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/

Issue #20920 has been updated by deivid (David Rodríguez). For what it's worth, this is not currently causing any issues in Bundler/RubyGems that I know of, so I changed the pending spec to track current Ruby's behavior and move on. From my side, this can be closed, but of course if Ruby maintainers think that it's worth and possible to bring more consistency here, I fully support that too. ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920#change-110905 * Author: deivid (David Rodríguez) * Status: Open * ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/

Issue #20920 has been updated by mame (Yusuke Endoh). Discussed at the dev meeting. @matz suggested that we try modifying it so that only the `load "foo.rb"` case is a full path, and leave the other cases as is. ``` $ ruby foo.rb foo.rb # This should be kept $ ruby ./foo.rb ./foo.rb # This should be kept $ ruby -e 'load "foo.rb"' foo.rb # This should be a full path $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb # This should be kept ``` ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920#change-111392 * Author: deivid (David Rodríguez) * Status: Open * ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/

Issue #20920 has been updated by ko1 (Koichi Sasada). Assignee set to nobu (Nobuyoshi Nakada) ---------------------------------------- Bug #20920: When loading a file, __FILE__ gets relative paths expanded only when they start with "./" https://bugs.ruby-lang.org/issues/20920#change-111876 * Author: deivid (David Rodríguez) * Status: Open * Assignee: nobu (Nobuyoshi Nakada) * ruby -v: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ``` $ cat foo.rb puts __FILE__ $ ruby foo.rb foo.rb $ ruby ./foo.rb ./foo.rb $ ruby -e 'load "foo.rb"' foo.rb $ ruby -e 'load "./foo.rb"' /full/path/to/foo.rb ``` More than an issue, this is mainly a question. In principle, it seems more consistent to me to either expand or not expand, but this is not causing real issues for me. I just want to figure out what to do with one pending spec in Bundler (https://github.com/rubygems/rubygems/blob/cd65092deb3168759820c613ecbc54cd9e...). -- https://bugs.ruby-lang.org/
participants (5)
-
Dan0042 (Daniel DeLorme)
-
deivid
-
ko1 (Koichi Sasada)
-
mame (Yusuke Endoh)
-
vo.x (Vit Ondruch)