From 50dabed79dbf89493b00de3fdd600ca91e2b16f4 Mon Sep 17 00:00:00 2001 From: Pavel Valodzka Date: Tue, 20 Jul 2010 16:35:00 +0300 Subject: [PATCH] Relative URI with host name should not use asset host --- .../lib/action_view/helpers/asset_tag_helper.rb | 2 +- actionpack/test/template/asset_tag_helper_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index a3c43d3..4d8945d 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -739,7 +739,7 @@ module ActionView end def is_uri?(path) - path =~ %r{^[-a-z]+://|^cid:} + path =~ %r{^([-a-z]+:)?//|^cid:} end # Pick an asset host for this source. Returns +nil+ if no host is set, diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 6d5e489..136fc3f 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -950,6 +950,12 @@ 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_relative_url_with_authority + # According to http://labs.apache.org/webarch/uri/rfc/rfc3986.html#relative-ref, example http://labs.apache.org/webarch/uri/rfc/rfc3986.html#relative-normal + @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') -- 1.6.1.9.g97c34