Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2-0-stable: Don't repeatedly add relative_url_root to asset sources. …

…References #10767 [tomtoday, Koz]

Merging [8740]


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8834 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b1aa67410a7d2a66b6454bcb5e7533f9f9985fd2 1 parent 291dad2
@NZKoz NZKoz authored
View
16 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -435,9 +435,11 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
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)
@@ -484,11 +486,15 @@ def rails_asset_id(source)
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)
View
4 actionpack/test/template/asset_tag_helper_test.rb
@@ -392,6 +392,8 @@ def test_should_compute_proper_path
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
@@ -404,6 +406,8 @@ def test_should_compute_proper_path_with_asset_host
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
Please sign in to comment.
Something went wrong with that request. Please try again.