aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-16 22:02:29 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-06-16 22:05:26 -0300
commit9f754e801f82aad8db760786ad3eb72cc7993108 (patch)
tree87789c45061ec571534ca33c79228c921e6e83dc
parent7092467f064832907f8de53b9da659b6de10d7e8 (diff)
downloadrails-9f754e801f82aad8db760786ad3eb72cc7993108.tar.gz
rails-9f754e801f82aad8db760786ad3eb72cc7993108.tar.bz2
rails-9f754e801f82aad8db760786ad3eb72cc7993108.zip
Compare host scheme using case-insensitive regexp
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\" />" Backport of #10969
-rw-r--r--actionpack/CHANGELOG.md21
-rw-r--r--actionpack/lib/action_view/asset_paths.rb2
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb40
3 files changed, 52 insertions, 11 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 9d50342867..585cad24db 100644
--- a/actionpack/CHANGELOG.md
+++ b/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 + Rafael Mendonça França*
+
* Fix explicit names on multiple file fields. If a file field tag has
the multiple option, it is turned into an array field (appending `[]`),
but if an explicit name is passed to `file_field` the `[]` is not
diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb
index c192d3704e..636a37b699 100644
--- a/actionpack/lib/action_view/asset_paths.rb
+++ b/actionpack/lib/action_view/asset_paths.rb
@@ -43,7 +43,7 @@ module ActionView
end
def is_uri?(path)
- path =~ %r{^[-a-z]+://|^(?:cid|data):|^//}
+ path =~ %r{^[-a-z]+://|^(?:cid|data):|^//}i
end
private
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index b1a01b53b1..6b1bc01f54 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -79,13 +79,17 @@ class AssetTagHelperTest < ActionView::TestCase
JavascriptPathToTag = {
%(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js),
%(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
- %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
+ %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js),
+ %(javascript_path("http://www.outside.com/foo.js")) => %(http://www.outside.com/foo.js),
+ %(javascript_path("HTTP://www.outside.com/foo.js")) => %(HTTP://www.outside.com/foo.js)
}
PathToJavascriptToTag = {
%(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
%(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
- %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
+ %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js),
+ %(path_to_javascript("http://www.outside.com/foo.js")) => %(http://www.outside.com/foo.js),
+ %(path_to_javascript("HTTP://www.outside.com/foo.js")) => %(HTTP://www.outside.com/foo.js)
}
JavascriptIncludeToTag = {
@@ -109,14 +113,18 @@ class AssetTagHelperTest < ActionView::TestCase
%(stylesheet_path("bank")) => %(/stylesheets/bank.css),
%(stylesheet_path("bank.css")) => %(/stylesheets/bank.css),
%(stylesheet_path('subdir/subdir')) => %(/stylesheets/subdir/subdir.css),
- %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css)
+ %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css),
+ %(stylesheet_path("http://www.outside.com/foo.css")) => %(http://www.outside.com/foo.css),
+ %(stylesheet_path("HTTP://www.outside.com/foo.css")) => %(HTTP://www.outside.com/foo.css)
}
PathToStyleToTag = {
%(path_to_stylesheet("style")) => %(/stylesheets/style.css),
%(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
%(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
- %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
+ %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss),
+ %(path_to_stylesheet("http://www.outside.com/foo.css")) => %(http://www.outside.com/foo.css),
+ %(path_to_stylesheet("HTTP://www.outside.com/foo.css")) => %(HTTP://www.outside.com/foo.css)
}
StyleLinkToTag = {
@@ -139,14 +147,18 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_path("xml")) => %(/images/xml),
%(image_path("xml.png")) => %(/images/xml.png),
%(image_path("dir/xml.png")) => %(/images/dir/xml.png),
- %(image_path("/dir/xml.png")) => %(/dir/xml.png)
+ %(image_path("/dir/xml.png")) => %(/dir/xml.png),
+ %(image_path("http://www.outside.com/foo.png")) => %(http://www.outside.com/foo.png),
+ %(image_path("HTTP://www.outside.com/foo.png")) => %(HTTP://www.outside.com/foo.png)
}
PathToImageToTag = {
%(path_to_image("xml")) => %(/images/xml),
%(path_to_image("xml.png")) => %(/images/xml.png),
%(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
- %(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
+ %(path_to_image("/dir/xml.png")) => %(/dir/xml.png),
+ %(path_to_image("http://www.outside.com/foo.png")) => %(http://www.outside.com/foo.png),
+ %(path_to_image("HTTP://www.outside.com/foo.png")) => %(HTTP://www.outside.com/foo.png)
}
ImageLinkToTag = {
@@ -181,14 +193,18 @@ class AssetTagHelperTest < ActionView::TestCase
%(video_path("xml")) => %(/videos/xml),
%(video_path("xml.ogg")) => %(/videos/xml.ogg),
%(video_path("dir/xml.ogg")) => %(/videos/dir/xml.ogg),
- %(video_path("/dir/xml.ogg")) => %(/dir/xml.ogg)
+ %(video_path("/dir/xml.ogg")) => %(/dir/xml.ogg),
+ %(video_path("http://www.outside.com/foo.ogg")) => %(http://www.outside.com/foo.ogg),
+ %(video_path("HTTP://www.outside.com/foo.ogg")) => %(HTTP://www.outside.com/foo.ogg)
}
PathToVideoToTag = {
%(path_to_video("xml")) => %(/videos/xml),
%(path_to_video("xml.ogg")) => %(/videos/xml.ogg),
%(path_to_video("dir/xml.ogg")) => %(/videos/dir/xml.ogg),
- %(path_to_video("/dir/xml.ogg")) => %(/dir/xml.ogg)
+ %(path_to_video("/dir/xml.ogg")) => %(/dir/xml.ogg),
+ %(path_to_video("http://www.outside.com/foo.ogg")) => %(http://www.outside.com/foo.ogg),
+ %(path_to_video("HTTP://www.outside.com/foo.ogg")) => %(HTTP://www.outside.com/foo.ogg)
}
VideoLinkToTag = {
@@ -211,14 +227,18 @@ class AssetTagHelperTest < ActionView::TestCase
%(audio_path("xml")) => %(/audios/xml),
%(audio_path("xml.wav")) => %(/audios/xml.wav),
%(audio_path("dir/xml.wav")) => %(/audios/dir/xml.wav),
- %(audio_path("/dir/xml.wav")) => %(/dir/xml.wav)
+ %(audio_path("/dir/xml.wav")) => %(/dir/xml.wav),
+ %(audio_path("http://www.outside.com/foo.wav")) => %(http://www.outside.com/foo.wav),
+ %(audio_path("HTTP://www.outside.com/foo.wav")) => %(HTTP://www.outside.com/foo.wav)
}
PathToAudioToTag = {
%(path_to_audio("xml")) => %(/audios/xml),
%(path_to_audio("xml.wav")) => %(/audios/xml.wav),
%(path_to_audio("dir/xml.wav")) => %(/audios/dir/xml.wav),
- %(path_to_audio("/dir/xml.wav")) => %(/dir/xml.wav)
+ %(path_to_audio("/dir/xml.wav")) => %(/dir/xml.wav),
+ %(path_to_audio("http://www.outside.com/foo.wav")) => %(http://www.outside.com/foo.wav),
+ %(path_to_audio("HTTP://www.outside.com/foo.wav")) => %(HTTP://www.outside.com/foo.wav)
}
AudioLinkToTag = {