Skip to content

Commit ddc411a

Browse files
authored
Merge pull request #684 from dakolech/master
Get rid off undefined method `start_with?' for nil:NilClass error
2 parents dd961f1 + b8523b3 commit ddc411a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/sprockets/path_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def set_pipeline(path, mime_exts, pipeline_exts, pipeline)
162162
def split_subpath(path, subpath)
163163
return "" if path == subpath
164164
path = File.join(path, ''.freeze)
165-
if subpath.start_with?(path)
165+
if subpath&.start_with?(path)
166166
subpath[path.length..-1]
167167
else
168168
nil

test/test_path_utils.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def test_split_subpath_from_root_path
109109
subpath = File.expand_path("../fixtures/default/app/application.js", __FILE__)
110110
assert_equal "app/application.js", split_subpath(path, subpath)
111111

112+
assert_equal nil, split_subpath(path, nil)
113+
112114
subpath = File.expand_path("../fixtures/default", __FILE__)
113115
assert_equal "", split_subpath(path, subpath)
114116

0 commit comments

Comments
 (0)