Skip to content

Commit 4dd4621

Browse files
josevalimrafaelfranca
authored andcommitted
Merge pull request rails#5020 from KL-7/fix-blank-image_tag-source
Render img tag with empty src if empty string is passed to image_tag.
1 parent 8ad8f61 commit 4dd4621

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

actionpack/lib/action_view/helpers/asset_tag_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def favicon_link_tag(source='/favicon.ico', options={})
272272
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
273273
# plugin authors are encouraged to do so.
274274
def image_path(source)
275-
asset_paths.compute_public_path(source, 'images')
275+
source.present? ? asset_paths.compute_public_path(source, 'images') : ""
276276
end
277277
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
278278

@@ -358,7 +358,7 @@ def image_tag(source, options = {})
358358

359359
src = options[:src] = path_to_image(source)
360360

361-
unless src =~ /^(?:cid|data):/
361+
unless src =~ /^(?:cid|data):/ || src.blank?
362362
options[:alt] = options.fetch(:alt){ image_alt(src) }
363363
end
364364

actionpack/test/template/asset_tag_helper_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def teardown
164164
%(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />),
165165
%(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />),
166166
%(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(<img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />),
167+
%(image_tag("")) => %(<img src="" />)
167168
}
168169

169170
FaviconLinkToTag = {

0 commit comments

Comments
 (0)