aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-06-29 10:48:47 +0200
committerYves Senn <yves.senn@gmail.com>2015-06-29 10:52:00 +0200
commitd4b0e5f59f599a386d43a7f4d005430e87ae7ec4 (patch)
tree1b5ea08e90994d3a7dfb3c804afd7b5df33cd0b1 /actionview
parentc90c9b2daa133341ad8ceca2d8010ba7d47c4957 (diff)
parent42a1b0c7c31400c762e2f8d1aff16338bbe8d63d (diff)
downloadrails-d4b0e5f59f599a386d43a7f4d005430e87ae7ec4.tar.gz
rails-d4b0e5f59f599a386d43a7f4d005430e87ae7ec4.tar.bz2
rails-d4b0e5f59f599a386d43a7f4d005430e87ae7ec4.zip
Merge pull request #20669 from akolomiychuk/image-path
Passing nil to image_tag
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md4
-rw-r--r--actionview/lib/action_view/helpers/asset_url_helper.rb2
-rw-r--r--actionview/test/template/asset_tag_helper_test.rb5
3 files changed, 11 insertions, 0 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 04c0850fba..069d181674 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Asset helpers raise `ArgumentError` when `nil` is passed as a source.
+
+ *Anton Kolomiychuk*
+
* Always attach the template digest to the cache key for collection caching
even when `virtual_path` is not available from the view context.
Which could happen if the rendering was done directly in the controller
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb
index ef4a6c98c0..b19dc25025 100644
--- a/actionview/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -121,6 +121,8 @@ module ActionView
# asset_path "application", type: :stylesheet # => /assets/application.css
# asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
def asset_path(source, options = {})
+ raise ArgumentError, "nil is not a valid asset source" if source.nil?
+
source = source.to_s
return "" unless source.present?
return source if source =~ URI_REGEXP
diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb
index 6e6ce20924..01fc66bed6 100644
--- a/actionview/test/template/asset_tag_helper_test.rb
+++ b/actionview/test/template/asset_tag_helper_test.rb
@@ -310,6 +310,11 @@ class AssetTagHelperTest < ActionView::TestCase
AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
+ def test_asset_path_tag_raises_an_error_for_nil_source
+ e = assert_raise(ArgumentError) { asset_path(nil) }
+ assert_equal("nil is not a valid asset source", e.message)
+ end
+
def test_asset_path_tag_to_not_create_duplicate_slashes
@controller.config.asset_host = "host/"
assert_dom_equal('http://host/foo', asset_path("foo"))