mirror of
https://github.com/github/rails.git
synced 2026-05-04 03:00:06 -04:00
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 #6310
This commit is contained in:
@@ -155,8 +155,13 @@ module Sprockets
|
||||
end
|
||||
|
||||
def rewrite_extension(source, dir, ext)
|
||||
if ext && File.extname(source) != ".#{ext}"
|
||||
"#{source}.#{ext}"
|
||||
source_ext = File.extname(source)
|
||||
if ext && source_ext != ".#{ext}"
|
||||
if !source_ext.empty? && asset_environment[source]
|
||||
source
|
||||
else
|
||||
"#{source}.#{ext}"
|
||||
end
|
||||
else
|
||||
source
|
||||
end
|
||||
|
||||
0
actionpack/test/fixtures/sprockets/app/stylesheets/style.ext
vendored
Normal file
0
actionpack/test/fixtures/sprockets/app/stylesheets/style.ext
vendored
Normal file
@@ -307,6 +307,9 @@ class SprocketsHelperTest < ActionView::TestCase
|
||||
assert_match %r{\A<link href="/assets/style-[0-9a-f]+.css" media="screen" rel="stylesheet" type="text/css" />\Z},
|
||||
stylesheet_link_tag("style", "style")
|
||||
|
||||
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")
|
||||
|
||||
@config.assets.compile = true
|
||||
@config.assets.debug = true
|
||||
assert_match %r{<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />},
|
||||
|
||||
Reference in New Issue
Block a user