diff options
-rw-r--r-- | lib/irb/workspace.rb | 7 | ||||
-rw-r--r-- | test/irb/test_workspace.rb | 13 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index aa28db5502..9ce84b60fa 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -111,8 +111,11 @@ EOF file, pos = @binding.eval('[__FILE__, __LINE__]') unless defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file] - return unless File.exist?(file) - lines = File.readlines(file) + begin + lines = File.readlines(file) + rescue SystemCallError + return + end end pos -= 1 diff --git a/test/irb/test_workspace.rb b/test/irb/test_workspace.rb index ce4c86d20b..970dc7fd14 100644 --- a/test/irb/test_workspace.rb +++ b/test/irb/test_workspace.rb @@ -32,6 +32,19 @@ module TestIRB end end + def test_code_around_binding_with_existing_unreadable_file + Tempfile.create do |f| + code = "IRB::WorkSpace.new(binding)\n" + f.print(code) + f.close + + File.chmod(0, f.path) + + workspace = eval(code, binding, f.path) + assert_equal(nil, workspace.code_around_binding) + end + end + def test_code_around_binding_with_script_lines__ with_script_lines do |script_lines| Tempfile.create do |f| |