From bfddb67197bf0b5c6ec17e2a35ece9190bec8bac Mon Sep 17 00:00:00 2001 From: Neil Souza Date: Wed, 26 Jul 2017 19:13:13 +0800 Subject: Fix #29632 - nil #path leads to NoMethodError in LoadError#is_missing? See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`. This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended. [Gannon McGibbon + Neil Souza] --- activesupport/test/core_ext/load_error_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/test/core_ext/load_error_test.rb') diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index 41b11d0c33..126aa51cb4 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -7,13 +7,20 @@ class TestLoadError < ActiveSupport::TestCase def test_with_require assert_raise(LoadError) { require "no_this_file_don't_exist" } end + def test_with_load assert_raise(LoadError) { load "nor_does_this_one" } end + def test_path begin load "nor/this/one.rb" rescue LoadError => e assert_equal "nor/this/one.rb", e.path end end + + def test_is_missing_with_nil_path + error = LoadError.new(nil) + assert_nothing_raised { error.is_missing?("anything") } + end end -- cgit v1.2.3