diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb
index 55a4c442fd..cb6737b94e 100644
--- a/actionpack/lib/action_view/helpers/asset_paths.rb
+++ b/actionpack/lib/action_view/helpers/asset_paths.rb
@@ -12,7 +12,7 @@ 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.
@@ -33,7 +33,7 @@ module ActionView
end
def is_uri?(path)
- path =~ %r{^[-a-z]+://|^cid:}
+ path =~ %r{^[-a-z]+://|^cid:|^//}
end
private
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 4a93def5a8..2abc806e97 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -66,6 +66,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(auto_discovery_link_tag(:xml)) => %(),
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(),
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(),
+ %(auto_discovery_link_tag(:rss, "//localhost/feed")) => %(),
%(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(),
%(auto_discovery_link_tag(:rss, {}, {:title => "My RSS"})) => %(),
%(auto_discovery_link_tag(nil, {}, {:type => "text/html"})) => %(),
@@ -100,6 +101,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(javascript_include_tag("http://example.com/all")) => %(),
%(javascript_include_tag("http://example.com/all.js")) => %(),
+ %(javascript_include_tag("//example.com/all.js")) => %(),
}
StylePathToTag = {
@@ -129,6 +131,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(stylesheet_link_tag("http://www.example.com/styles/style")) => %(),
%(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(),
+ %(stylesheet_link_tag("//www.example.com/styles/style.css")) => %(),
}
ImagePathToTag = {
@@ -157,6 +160,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_tag("slash..png")) => %(
),
%(image_tag(".pdf.png")) => %(
),
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(
),
+ %(image_tag("//www.rubyonrails.com/images/rails.png")) => %(
),
%(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(
),
%(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(
),
%(image_tag("mouse.png", :alt => nil)) => %(
)
@@ -195,6 +199,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(video_tag("error.avi", "size" => "100 x 100")) => %(),
%(video_tag("error.avi", "size" => "x")) => %(),
%(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(),
+ %(video_tag("//media.rubyonrails.org/video/rails_blog_2.mov")) => %(),
%(video_tag(["multiple.ogg", "multiple.avi"])) => %(),
%(video_tag(["multiple.ogg", "multiple.avi"], :size => "160x120", :controls => true)) => %()
}
@@ -217,6 +222,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(audio_tag("xml.wav")) => %(),
%(audio_tag("rss.wav", :autoplay => true, :controls => true)) => %(),
%(audio_tag("http://media.rubyonrails.org/audio/rails_blog_2.mov")) => %(),
+ %(audio_tag("//media.rubyonrails.org/audio/rails_blog_2.mov")) => %(),
}
def test_auto_discovery_link_tag
@@ -505,6 +511,10 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(
), image_tag("http://www.example.com/rails.png")
end
+ def test_should_skip_asset_id_on_scheme_relative_url
+ assert_equal %(
), image_tag("//www.example.com/rails.png")
+ end
+
def test_should_use_preset_asset_id
ENV["RAILS_ASSET_ID"] = "4500"
assert_equal %(
), image_tag("rails.png")
@@ -1095,6 +1105,11 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
assert_dom_equal(%(), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
end
+ def test_should_ignore_asset_host_on_scheme_relative_url
+ @controller.config.asset_host = "http://assets.example.com"
+ assert_dom_equal(%(), stylesheet_link_tag("//bar.example.com/stylesheets/style.css"))
+ end
+
def test_should_wildcard_asset_host_between_zero_and_four
@controller.config.asset_host = 'http://a%d.example.com'
assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png'))