From 2715ef69a0842dd8295ed4d90509eb6ebbafd456 Mon Sep 17 00:00:00 2001 From: ojab Date: Wed, 22 Sep 2021 21:49:39 +0000 Subject: [PATCH] Optimize relative `../` paths resolution --- lib/bootsnap/load_path_cache/cache.rb | 2 +- test/load_path_cache/cache_test.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bootsnap/load_path_cache/cache.rb b/lib/bootsnap/load_path_cache/cache.rb index 837b72b2..4599a87d 100644 --- a/lib/bootsnap/load_path_cache/cache.rb +++ b/lib/bootsnap/load_path_cache/cache.rb @@ -50,7 +50,7 @@ def find(feature, try_extensions: true) return feature if absolute_path?(feature) - if feature.start_with?('./') + if feature.start_with?('./', '../') return try_extensions ? expand_path(feature) : File.expand_path(feature).freeze end diff --git a/test/load_path_cache/cache_test.rb b/test/load_path_cache/cache_test.rb index bd862605..9b3a2c3b 100644 --- a/test/load_path_cache/cache_test.rb +++ b/test/load_path_cache/cache_test.rb @@ -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'))