From f0707c09689c731ba397a893432688f58b845922 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 15 Jun 2013 16:22:14 -0700 Subject: [PATCH] Prevent relative asset helper from munging data URIs. Closes #938. --- middleman-core/features/relative_assets.feature | 11 +++++++++++ .../middleman-more/core_extensions/default_helpers.rb | 4 ++-- .../lib/middleman-more/extensions/relative_assets.rb | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/middleman-core/features/relative_assets.feature b/middleman-core/features/relative_assets.feature index 2a74159f..1ebafdfa 100644 --- a/middleman-core/features/relative_assets.feature +++ b/middleman-core/features/relative_assets.feature @@ -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 '' + + 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 '' \ No newline at end of file diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index b9dbc2dc..aa030882 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -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) diff --git a/middleman-core/lib/middleman-more/extensions/relative_assets.rb b/middleman-core/lib/middleman-more/extensions/relative_assets.rb index 2679727f..82b79dfa 100644 --- a/middleman-core/lib/middleman-more/extensions/relative_assets.rb +++ b/middleman-core/lib/middleman-more/extensions/relative_assets.rb @@ -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)