Skip to content

Commit d4b0e5f

Browse files
committed
Merge pull request rails#20669 from akolomiychuk/image-path
Passing nil to image_tag
2 parents c90c9b2 + 42a1b0c commit d4b0e5f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

actionview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Asset helpers raise `ArgumentError` when `nil` is passed as a source.
2+
3+
*Anton Kolomiychuk*
4+
15
* Always attach the template digest to the cache key for collection caching
26
even when `virtual_path` is not available from the view context.
37
Which could happen if the rendering was done directly in the controller

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, "nil is not a valid 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+
e = assert_raise(ArgumentError) { asset_path(nil) }
315+
assert_equal("nil is not a valid asset source", e.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)