Prevent relative asset helper from munging data URIs. Closes #938.
This commit is contained in:
parent
9320007be6
commit
f0707c0968
|
@ -134,3 +134,14 @@ Feature: Relative Assets
|
|||
And the Server is running at "relative-assets-app"
|
||||
When I go to "/sub/image_tag.html"
|
||||
Then I should see '<img src="../img/blank.gif" />'
|
||||
|
||||
Scenario: Relative assets should not break data URIs in image_tag
|
||||
Given a fixture app "relative-assets-app"
|
||||
Given "relative_assets" feature is "enabled"
|
||||
And a file named "source/sub/image_tag.html.erb" with:
|
||||
"""
|
||||
<%= image_tag "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" %>
|
||||
"""
|
||||
And the Server is running at "relative-assets-app"
|
||||
When I go to "/sub/image_tag.html"
|
||||
Then I should see '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />'
|
|
@ -134,7 +134,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# @param [String] source The path to the file
|
||||
# @return [String]
|
||||
def asset_path(kind, source)
|
||||
return source if source.to_s.include?('//')
|
||||
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
|
||||
asset_folder = case kind
|
||||
when :css then css_dir
|
||||
when :js then js_dir
|
||||
|
@ -157,7 +157,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
# @return [String] The fully qualified asset url
|
||||
def asset_url(path, prefix="")
|
||||
# Don't touch assets which already have a full path
|
||||
if path.include?("//")
|
||||
if path.include?('//') or path.start_with?('data:')
|
||||
path
|
||||
else # rewrite paths to use their destination path
|
||||
path = File.join(prefix, path)
|
||||
|
|
|
@ -18,7 +18,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|||
def asset_url(path, prefix="")
|
||||
path = super(path, prefix)
|
||||
|
||||
if path.include?("//") || !current_resource
|
||||
if path.include?('//') || path.start_with?('data:') || !current_resource
|
||||
path
|
||||
else
|
||||
current_dir = Pathname('/' + current_resource.destination_path)
|
||||
|
|
Loading…
Reference in a new issue