diff options
author | Anton Kolomiychuk <kolomiychuk.anton@gmail.com> | 2015-06-23 00:36:19 +0600 |
---|---|---|
committer | Anton Kolomiychuk <kolomiychuk.anton@gmail.com> | 2015-06-29 14:03:29 +0600 |
commit | 42a1b0c7c31400c762e2f8d1aff16338bbe8d63d (patch) | |
tree | 5833d82f357dbd5fb159b5c749bec33c85138dca /actionview | |
parent | 40bdf0dd4c1f4425b9a91c5fc8b570d35dfd4d73 (diff) | |
download | rails-42a1b0c7c31400c762e2f8d1aff16338bbe8d63d.tar.gz rails-42a1b0c7c31400c762e2f8d1aff16338bbe8d63d.tar.bz2 rails-42a1b0c7c31400c762e2f8d1aff16338bbe8d63d.zip |
Add nil check in asset_path
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/asset_url_helper.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/asset_tag_helper_test.rb | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb index ef4a6c98c0..f36e9a108f 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, "Cannot pass nil as 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..d8a2a8bad0 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 + exception = assert_raise(ArgumentError) { asset_path(nil) } + assert_equal("Cannot pass nil as asset source", exception.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")) |