Permalink
Browse files

Fix asset tags for files with more than one dot

After the fix done in 39f9f02, there are cases that will not work
correctly. If you have file with "2 extensions", like foo.min.js and you
reference the file without extension, like:

    javascript_include_tag "foo.min"

it will fail because sprockets finds foo.min.js with foo.min argument.

This commit fixes this case and will get the right file even when
referrencing it without extension.

(closes #6598)
  • Loading branch information...
1 parent f550d4d commit 10537ba885c77ca1d4f14624d54e8987e32454fb @drogus committed Jun 2, 2012
View
4 actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -157,7 +157,9 @@ def rewrite_asset_path(source, dir, options = {})
def rewrite_extension(source, dir, ext)
source_ext = File.extname(source)
if ext && source_ext != ".#{ext}"
- if !source_ext.empty? && asset_environment[source]
+ asset = asset_environment[source]
+ if !source_ext.empty? && asset &&
+ asset.pathname.to_s =~ /#{source}\Z/
source
else
"#{source}.#{ext}"
View
0 actionpack/test/fixtures/sprockets/app/javascripts/foo.min.js
No changes.
View
0 actionpack/test/fixtures/sprockets/app/stylesheets/style.min.css
No changes.
View
6 actionpack/test/template/sprockets_helper_test.rb
@@ -257,6 +257,9 @@ def compute_host(source, request, options = {})
assert_match %r{\A<script src="/assets/xmlhr-[0-9a-f]+.js" type="text/javascript"></script>\Z},
javascript_include_tag("xmlhr", "xmlhr")
+ assert_match %r{\A<script src="/assets/foo.min-[0-9a-f]+.js" type="text/javascript"></script>\Z},
+ javascript_include_tag("foo.min")
+
@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<script src="/javascripts/application.js" type="text/javascript"></script>},
@@ -310,6 +313,9 @@ def compute_host(source, request, options = {})
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.ext" media="screen" rel="stylesheet" type="text/css" />\Z},
stylesheet_link_tag("style.ext")
+ assert_match %r{\A<link href="/assets/style.min-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
+ stylesheet_link_tag("style.min")
+
@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},

0 comments on commit 10537ba

Please sign in to comment.