Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use a case insensitive URI Regexp for #asset_path

Context: https://gist.github.com/radar/5793814

The `URI_REGEXP` that various AssetUrl helpers use is currently case
sensitive when checking for a URI scheme. This means if you try to pass
a URL like `HTTP://www.example.com/path/to/image.jpg`, you end up with
a bogus asset path: `/assets/HTTP://www.example.com/path/to/image.jpg`.

URLs are case insensitive, so this regexp should be as well.

Signed-off-by: David Celis <me@davidcel.is>
  • Loading branch information...
commit 8fc3427646e932c3a1fb9f9794364866f030595e 1 parent 0f89689
@davidcelis davidcelis authored
View
2  actionpack/lib/action_view/helpers/asset_url_helper.rb
@@ -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
View
7 actionpack/test/template/asset_tag_helper_test.rb
@@ -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)
@@ -445,8 +448,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
Please sign in to comment.
Something went wrong with that request. Please try again.