1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #5020 from KL-7/fix-blank-image_tag-source

Render img tag with empty src if empty string is passed to image_tag.
This commit is contained in:
José Valim 2012-05-17 23:42:37 -07:00
commit 6bb86e1f3f
2 changed files with 3 additions and 2 deletions

View file

@ -274,7 +274,7 @@ module ActionView
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
# plugin authors are encouraged to do so.
def image_path(source)
asset_paths.compute_public_path(source, 'images')
source.present? ? asset_paths.compute_public_path(source, 'images') : ""
end
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
@ -377,7 +377,7 @@ module ActionView
src = options[:src] = path_to_image(source)
unless src =~ /^(?:cid|data):/
unless src =~ /^(?:cid|data):/ || src.blank?
options[:alt] = options.fetch(:alt){ image_alt(src) }
end

View file

@ -205,6 +205,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />),
%(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />),
%(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />),
%(image_tag("")) => %(<img src="" />)
}
FaviconLinkToTag = {