Skip to content

Commit

Permalink
Merge pull request #10969 from davidcelis/case-insensitive-asset-path
Browse files Browse the repository at this point in the history
Use a case insensitive URI Regexp for #asset_path
  • Loading branch information
rafaelfranca committed Jun 17, 2013
1 parent 57c51e7 commit b4d2943
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
21 changes: 21 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,5 +1,26 @@
## unreleased ##

* Use a case insensitive URI Regexp for #asset_path.

This fix a problem where the same asset path using different case are generating
different URIs.

Before:

image_tag("HTTP://google.com")
# => "<img alt=\"Google\" src=\"/assets/HTTP://google.com\" />"
image_tag("http://google.com")
# => "<img alt=\"Google\" src=\"http://google.com\" />"

After:

image_tag("HTTP://google.com")
# => "<img alt=\"Google\" src=\"HTTP://google.com\" />"
image_tag("http://google.com")
# => "<img alt=\"Google\" src=\"http://google.com\" />"

*David Celis*

* Add `has_named_route?(route_name)` to the mapper API.

*José Valim*
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/asset_url_helper.rb
Expand Up @@ -105,7 +105,7 @@ module Helpers
# )
#
module AssetUrlHelper
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i

# Computes the path to asset in public directory. If :type
# options is set, a file extension will be appended and scoped
Expand Down
7 changes: 5 additions & 2 deletions actionpack/test/template/asset_tag_helper_test.rb
Expand Up @@ -48,6 +48,9 @@ def url_for(*args)
%(asset_path("style.min")) => %(/style.min),
%(asset_path("style.min.css")) => %(/style.min.css),

%(asset_path("http://www.outside.com/image.jpg")) => %(http://www.outside.com/image.jpg),
%(asset_path("HTTP://www.outside.com/image.jpg")) => %(HTTP://www.outside.com/image.jpg),

%(asset_path("style", type: :stylesheet)) => %(/stylesheets/style.css),
%(asset_path("xmlhr", type: :javascript)) => %(/javascripts/xmlhr.js),
%(asset_path("xml.png", type: :image)) => %(/images/xml.png)
Expand Down Expand Up @@ -443,8 +446,8 @@ def test_image_alt
[nil, '/', '/foo/bar/', 'foo/bar/'].each do |prefix|
assert_equal 'Rails', image_alt("#{prefix}rails.png")
assert_equal 'Rails', image_alt("#{prefix}rails-9c0a079bdd7701d7e729bd956823d153.png")
assert_equal 'Long file name with hyphens', image_alt("#{prefix}long-file-name-with-hyphens.png")
assert_equal 'Long file name with underscores', image_alt("#{prefix}long_file_name_with_underscores.png")
assert_equal 'Long file name with hyphens', image_alt("#{prefix}long-file-name-with-hyphens.png")
assert_equal 'Long file name with underscores', image_alt("#{prefix}long_file_name_with_underscores.png")
end
end

Expand Down

0 comments on commit b4d2943

Please sign in to comment.