Skip to content

Commit 39f9f02

Browse files
committed
Assets: don't add extension if other given and file exists
We should lookup if asset without appended extension exists. When sprockets are disabled the asset tag helpers incorporate this logic. When sprockets are enabled we should have the same logic. For example, we have style.ext file in app/assets/stylesheets and we use stylesheet_link_tag in the layout. In this case we should have /assets/style.ext instead of /assets/style.ext.css in the output. Closes rails#6310
1 parent 64e12ff commit 39f9f02

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

actionpack/lib/sprockets/helpers/rails_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,13 @@ def rewrite_asset_path(source, dir, options = {})
155155
end
156156

157157
def rewrite_extension(source, dir, ext)
158-
if ext && File.extname(source) != ".#{ext}"
159-
"#{source}.#{ext}"
158+
source_ext = File.extname(source)
159+
if ext && source_ext != ".#{ext}"
160+
if !source_ext.empty? && asset_environment[source]
161+
source
162+
else
163+
"#{source}.#{ext}"
164+
end
160165
else
161166
source
162167
end

actionpack/test/fixtures/sprockets/app/stylesheets/style.ext

Whitespace-only changes.

actionpack/test/template/sprockets_helper_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ def compute_host(source, request, options = {})
307307
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
308308
stylesheet_link_tag("style", "style")
309309

310+
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.ext" media="screen" rel="stylesheet" type="text/css" />\Z},
311+
stylesheet_link_tag("style.ext")
312+
310313
@config.assets.compile = true
311314
@config.assets.debug = true
312315
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},

0 commit comments

Comments
 (0)