Skip to content

Commit 42a1b0c

Browse files
committed
Add nil check in asset_path
1 parent 40bdf0d commit 42a1b0c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

actionview/lib/action_view/helpers/asset_url_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ module AssetUrlHelper
121121
# asset_path "application", type: :stylesheet # => /assets/application.css
122122
# asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
123123
def asset_path(source, options = {})
124+
raise ArgumentError, "Cannot pass nil as asset source" if source.nil?
125+
124126
source = source.to_s
125127
return "" unless source.present?
126128
return source if source =~ URI_REGEXP

actionview/test/template/asset_tag_helper_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ def test_asset_path_tag
310310
AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
311311
end
312312

313+
def test_asset_path_tag_raises_an_error_for_nil_source
314+
exception = assert_raise(ArgumentError) { asset_path(nil) }
315+
assert_equal("Cannot pass nil as asset source", exception.message)
316+
end
317+
313318
def test_asset_path_tag_to_not_create_duplicate_slashes
314319
@controller.config.asset_host = "host/"
315320
assert_dom_equal('http://host/foo', asset_path("foo"))

0 commit comments

Comments
 (0)