Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Return an absolute instead of relative path from an asset url in the …

…case of the `asset_host` proc returning nil

(cherry picked from commit d005777)

Conflicts:
	actionpack/lib/action_view/helpers/asset_url_helper.rb
	actionview/CHANGELOG.md
  • Loading branch information...
commit 0997ceb600afdda11d2861c5bdd09b46abe182cb 1 parent f6007d6
Jolyon Pawlyn authored pixeltrix committed
View
5 actionpack/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Return an absolute instead of relative path from an asset url in the case
+ of the `asset_host` proc returning nil
+
+ *Jolyon Pawlyn*
+
* Prepend a JS comment to JSONP callbacks. Addresses CVE-2014-4671
("Rosetta Flash")
View
2  actionpack/lib/action_view/helpers/asset_url_helper.rb
@@ -192,7 +192,6 @@ def compute_asset_path(source, options = {})
def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
host = config.asset_host if defined? config.asset_host
- host ||= request.base_url if request && options[:protocol] == :request
if host.respond_to?(:call)
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
@@ -203,6 +202,7 @@ def compute_asset_host(source = "", options = {})
host = host % (Zlib.crc32(source) % 4)
end
+ host ||= request.base_url if request && options[:protocol] == :request
return unless host
if host =~ URI_REGEXP
View
8 actionpack/test/template/asset_tag_helper_test.rb
@@ -552,6 +552,14 @@ def test_image_path_with_asset_host_proc_returning_nil
assert_equal "http://cdn.example.com/images/file.png", image_path("file.png")
end
+ def test_image_url_with_asset_host_proc_returning_nil
+ @controller.config.asset_host = Proc.new { nil }
+ @controller.request = Struct.new(:base_url, :script_name).new("http://www.example.com", nil)
+
+ assert_equal "/images/rails.png", image_path("rails.png")
+ assert_equal "http://www.example.com/images/rails.png", image_url("rails.png")
+ end
+
def test_caching_image_path_with_caching_and_proc_asset_host_using_request
@controller.config.asset_host = Proc.new do |source, request|
if request.ssl?
Please sign in to comment.
Something went wrong with that request. Please try again.