aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-01-27 01:10:48 +0000
committerMichael Koziarski <michael@koziarski.com>2008-01-27 01:10:48 +0000
commit10aa728e8ba423e43fb96fa234309819e1a99574 (patch)
treec5924295150ce464e283a7d097c56684bc2ae491
parent5ac3a9bd0b4cfd6aa7ad585ae6dde206c2e32bb0 (diff)
downloadrails-10aa728e8ba423e43fb96fa234309819e1a99574.tar.gz
rails-10aa728e8ba423e43fb96fa234309819e1a99574.tar.bz2
rails-10aa728e8ba423e43fb96fa234309819e1a99574.zip
Don't repeatedly add relative_url_root to asset sources. Closes #10767 [tomtoday, Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8740 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb16
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb4
2 files changed, 15 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 12fbbb0dd6..883cd31373 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -450,9 +450,11 @@ module ActionView
else
source = "/#{dir}/#{source}" unless source[0] == ?/
if has_request
- source = "#{@controller.request.relative_url_root}#{source}"
+ unless source =~ %r{^#{@controller.request.relative_url_root}/}
+ source = "#{@controller.request.relative_url_root}#{source}"
+ end
end
- rewrite_asset_path!(source)
+ source = rewrite_asset_path(source)
if include_host
host = compute_asset_host(source)
@@ -504,11 +506,15 @@ module ActionView
end
end
- # Break out the asset path rewrite so you wish to put the asset id
+ # Break out the asset path rewrite in case plugins wish to put the asset id
# someplace other than the query string.
- def rewrite_asset_path!(source)
+ def rewrite_asset_path(source)
asset_id = rails_asset_id(source)
- source << "?#{asset_id}" if !asset_id.blank?
+ if asset_id.blank?
+ source
+ else
+ source + "?#{asset_id}"
+ end
end
def javascript_src_tag(source, options)
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 3b614ad2a0..ffd1d955e1 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -432,6 +432,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
end
def test_should_ignore_relative_root_path_on_complete_url
@@ -444,6 +446,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse2.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
ensure
ActionController::Base.asset_host = ""
end