Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty host for an asset url when asset_host proc returns nil #16161

Merged
merged 1 commit into from Jul 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions actionview/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*

* Fix `html_escape_once` to properly handle hex escape sequences (e.g. ᨫ) * Fix `html_escape_once` to properly handle hex escape sequences (e.g. ᨫ)


*John F. Douthat* *John F. Douthat*
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/asset_url_helper.rb
Expand Up @@ -203,7 +203,6 @@ def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request) request = self.request if respond_to?(:request)
host = options[:host] host = options[:host]
host ||= config.asset_host if defined? config.asset_host host ||= config.asset_host if defined? config.asset_host
host ||= request.base_url if request && options[:protocol] == :request


if host.respond_to?(:call) if host.respond_to?(:call)
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
Expand All @@ -214,6 +213,7 @@ def compute_asset_host(source = "", options = {})
host = host % (Zlib.crc32(source) % 4) host = host % (Zlib.crc32(source) % 4)
end end


host ||= request.base_url if request && options[:protocol] == :request
return unless host return unless host


if host =~ URI_REGEXP if host =~ URI_REGEXP
Expand Down
8 changes: 8 additions & 0 deletions actionview/test/template/asset_tag_helper_test.rb
Expand Up @@ -546,6 +546,14 @@ def test_image_path_with_asset_host_proc_returning_nil
assert_equal "http://cdn.example.com/images/file.png", image_path("file.png") assert_equal "http://cdn.example.com/images/file.png", image_path("file.png")
end 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 def test_caching_image_path_with_caching_and_proc_asset_host_using_request
@controller.config.asset_host = Proc.new do |source, request| @controller.config.asset_host = Proc.new do |source, request|
if request.ssl? if request.ssl?
Expand Down