Skip to content
This repository
Browse code

Using the sum of bytes instead the hash of the path when replacing th…

…e wildcard of the assets path because in ruby 1.9 is not consistent
  • Loading branch information...
commit f6a6b51ae551b7f936e974cba3ad4b30422d6804 1 parent 298a083
Albert Callarisa acroca authored
3  actionpack/lib/action_view/asset_paths.rb
@@ -111,7 +111,8 @@ def compute_asset_host(source)
111 111 args << current_request if (arity > 1 || arity < 0) && has_request?
112 112 host.call(*args)
113 113 else
114   - (host =~ /%d/) ? host % (source.hash % 4) : host
  114 + source_num = source.bytes.sum
  115 + (host =~ /%d/) ? host % (source_num % 4) : host
115 116 end
116 117 end
117 118 end
5 actionpack/test/template/asset_tag_helper_test.rb
@@ -689,9 +689,9 @@ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
689 689 @controller.config.asset_host = 'http://a%d.example.com'
690 690 config.perform_caching = true
691 691
692   - hash = '/javascripts/cache/money.js'.hash % 4
  692 + number = '/javascripts/cache/money.js'.bytes.sum % 4
693 693 assert_dom_equal(
694   - %(<script src="http://a#{hash}.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
  694 + %(<script src="http://a#{number}.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
695 695 javascript_include_tag(:all, :cache => "cache/money")
696 696 )
697 697
@@ -1129,6 +1129,7 @@ def test_should_ignore_asset_host_on_scheme_relative_url
1129 1129 end
1130 1130
1131 1131 def test_should_wildcard_asset_host_between_zero_and_four
  1132 + String.any_instance.expects(:hash).times(0)
1132 1133 @controller.config.asset_host = 'http://a%d.example.com'
1133 1134 assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png'))
1134 1135 end

0 comments on commit f6a6b51

Xavier Noria

Just wondering, is the sum better than just taking source.bytes % 4? I think source.bytes will generally be evenly distributed mod 4, a priori I see no bias in the number of bytes of an asset.

Xavier Noria

Well, the last char may have a bias, it will generally be "s", (css, js), g (png, jpg)... nah, forget the comment.

Aaron Patterson

Is this hash supposed to be unique?

Aaron Patterson

This is not a good assertion. Are we not allowed to use strings as hash keys in our implementation?

Please sign in to comment.
Something went wrong with that request. Please try again.