diff --git a/lib/sprockets/path_utils.rb b/lib/sprockets/path_utils.rb index c4d37ba75..d46f201a5 100644 --- a/lib/sprockets/path_utils.rb +++ b/lib/sprockets/path_utils.rb @@ -162,7 +162,7 @@ def set_pipeline(path, mime_exts, pipeline_exts, pipeline) def split_subpath(path, subpath) return "" if path == subpath path = File.join(path, ''.freeze) - if subpath.start_with?(path) + if subpath&.start_with?(path) subpath[path.length..-1] else nil diff --git a/test/test_path_utils.rb b/test/test_path_utils.rb index 669a85a04..59a2490a8 100644 --- a/test/test_path_utils.rb +++ b/test/test_path_utils.rb @@ -109,6 +109,8 @@ def test_split_subpath_from_root_path subpath = File.expand_path("../fixtures/default/app/application.js", __FILE__) assert_equal "app/application.js", split_subpath(path, subpath) + assert_equal nil, split_subpath(path, nil) + subpath = File.expand_path("../fixtures/default", __FILE__) assert_equal "", split_subpath(path, subpath)