Skip to content

Commit

Permalink
Optimize relative ../ paths resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ojab committed Sep 22, 2021
1 parent a444a62 commit 9f386d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bootsnap/load_path_cache/cache.rb
Expand Up @@ -50,7 +50,7 @@ def find(feature, try_extensions: true)

return feature if absolute_path?(feature)

if feature.start_with?('./')
if feature.start_with?('./') || feature.start_with?('../')
return try_extensions ? expand_path(feature) : File.expand_path(feature).freeze
end

Expand Down
3 changes: 3 additions & 0 deletions test/load_path_cache/cache_test.rb
Expand Up @@ -58,9 +58,12 @@ def test_simple
def test_extension_append_for_relative_paths
po = [@dir1]
cache = Cache.new(NullCache, po)
dir1_basename = File.basename(@dir1)
Dir.chdir(@dir1) do
assert_equal("#{@dir1}/a.rb", cache.find('./a'))
assert_equal("#{@dir1}/a", cache.find('./a', try_extensions: false))
assert_equal("#{@dir1}/a.rb", cache.find("../#{dir1_basename}/a"))
assert_equal("#{@dir1}/a", cache.find("../#{dir1_basename}/a", try_extensions: false))
assert_equal("#{@dir1}/dl#{DLEXT}", cache.find('./dl'))
assert_equal("#{@dir1}/dl", cache.find('./dl', try_extensions: false))
assert_equal("#{@dir1}/enoent", cache.find('./enoent'))
Expand Down

0 comments on commit 9f386d1

Please sign in to comment.