From b49a1192d3d7f2dffff742fc154c8b3d2533b621 Mon Sep 17 00:00:00 2001 From: Chad Krsek Date: Mon, 25 Apr 2011 21:57:28 -0700 Subject: asset helpers should understand scheme-relative URLs --- actionpack/lib/action_view/helpers/asset_paths.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb index 55a4c442fd..0429e60cd5 100644 --- a/actionpack/lib/action_view/helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_paths.rb @@ -12,13 +12,13 @@ module ActionView @controller = controller end - # Add the extension +ext+ if not present. Return full URLs otherwise untouched. + # Add the extension +ext+ if not present. Return full or scheme-relative URLs otherwise untouched. # Prefix with /dir/ if lacking a leading +/+. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include # asset host, if configured, with the correct request protocol. def compute_public_path(source, dir, ext = nil, include_host = true) source = source.to_s - return source if is_uri?(source) + return source if is_uri?(source) || is_scheme_relative_uri?(source) source = rewrite_extension(source, dir, ext) if ext source = "/#{dir}/#{source}" unless source[0] == ?/ @@ -36,6 +36,13 @@ module ActionView path =~ %r{^[-a-z]+://|^cid:} end + # A URI relative to a base URI's scheme? + # See http://labs.apache.org/webarch/uri/rfc/rfc3986.html#relative-normal + # "//g" => "http://g" + def is_scheme_relative_uri?(path) + path =~ %r{^//} + end + private def rewrite_extension(source, dir, ext) -- cgit v1.2.3