From 6cf2da0cd33c0d4bddb32e5a5cd7638e059b7eed Mon Sep 17 00:00:00 2001 From: elfham <38372058+elfham@users.noreply.github.com> Date: Mon, 25 Sep 2023 23:37:16 +0900 Subject: [PATCH 1/2] Fix config.rb to File.expand_path $include path in inputrc --- lib/reline/config.rb | 2 +- test/reline/test_config.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 87726393a6..4c07a73701 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -252,7 +252,7 @@ def handle_directive(directive, file, no) end @skip_section = @if_stack.pop when 'include' - read(args) + read(File.expand_path(args)) end end diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index b16aed720a..7e32c0017d 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -160,6 +160,22 @@ def test_include assert_equal :audible, @config.instance_variable_get(:@bell_style) end + def test_include_expand_path + pwd = Dir.pwd + File.open('included_partial', 'wt') do |f| + f.write(<<~PARTIAL_LINES) + set bell-style on + PARTIAL_LINES + end + # '~/../ (...) /../PATH_TO/included_partial' => '/PATH_TO/included_partial' + path_to_be_expanded = File.join('~', ['..'] * 100, pwd, 'included_partial') + @config.read_lines(<<~LINES.lines) + $include #{path_to_be_expanded} + LINES + + assert_equal :audible, @config.instance_variable_get(:@bell_style) + end + def test_if @config.read_lines(<<~LINES.lines) $if Ruby From 79be78bb730e920c9663377b8c188e7bf2df1f4e Mon Sep 17 00:00:00 2001 From: elfham <38372058+elfham@users.noreply.github.com> Date: Tue, 26 Sep 2023 12:38:12 +0900 Subject: [PATCH 2/2] fix bug of test_include_expand_path on Windows --- test/reline/test_config.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index 7e32c0017d..9ead047ce4 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -161,19 +161,20 @@ def test_include end def test_include_expand_path - pwd = Dir.pwd + home_backup = ENV['HOME'] File.open('included_partial', 'wt') do |f| f.write(<<~PARTIAL_LINES) set bell-style on PARTIAL_LINES end - # '~/../ (...) /../PATH_TO/included_partial' => '/PATH_TO/included_partial' - path_to_be_expanded = File.join('~', ['..'] * 100, pwd, 'included_partial') + ENV['HOME'] = Dir.pwd @config.read_lines(<<~LINES.lines) - $include #{path_to_be_expanded} + $include ~/included_partial LINES assert_equal :audible, @config.instance_variable_get(:@bell_style) + ensure + ENV['HOME'] = home_backup end def test_if