提交 d4b0e5f5 编写于 作者: Y Yves Senn

Merge pull request #20669 from akolomiychuk/image-path

Passing nil to image_tag
* 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
......
......@@ -121,6 +121,8 @@ module AssetUrlHelper
# 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
......
......@@ -310,6 +310,11 @@ def test_asset_path_tag
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"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册