mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Prevent relative asset helper from munging data URIs. Closes #938.
This commit is contained in:
parent
9320007be6
commit
f0707c0968
3 changed files with 14 additions and 3 deletions
|
@ -134,3 +134,14 @@ Feature: Relative Assets
|
||||||
And the Server is running at "relative-assets-app"
|
And the Server is running at "relative-assets-app"
|
||||||
When I go to "/sub/image_tag.html"
|
When I go to "/sub/image_tag.html"
|
||||||
Then I should see '<img src="../img/blank.gif" />'
|
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
|
# @param [String] source The path to the file
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def asset_path(kind, source)
|
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
|
asset_folder = case kind
|
||||||
when :css then css_dir
|
when :css then css_dir
|
||||||
when :js then js_dir
|
when :js then js_dir
|
||||||
|
@ -157,7 +157,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
||||||
# @return [String] The fully qualified asset url
|
# @return [String] The fully qualified asset url
|
||||||
def asset_url(path, prefix="")
|
def asset_url(path, prefix="")
|
||||||
# Don't touch assets which already have a full path
|
# Don't touch assets which already have a full path
|
||||||
if path.include?("//")
|
if path.include?('//') or path.start_with?('data:')
|
||||||
path
|
path
|
||||||
else # rewrite paths to use their destination path
|
else # rewrite paths to use their destination path
|
||||||
path = File.join(prefix, path)
|
path = File.join(prefix, path)
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
||||||
def asset_url(path, prefix="")
|
def asset_url(path, prefix="")
|
||||||
path = super(path, prefix)
|
path = super(path, prefix)
|
||||||
|
|
||||||
if path.include?("//") || !current_resource
|
if path.include?('//') || path.start_with?('data:') || !current_resource
|
||||||
path
|
path
|
||||||
else
|
else
|
||||||
current_dir = Pathname('/' + current_resource.destination_path)
|
current_dir = Pathname('/' + current_resource.destination_path)
|
||||||
|
|
Loading…
Reference in a new issue