diff options
Diffstat (limited to 'actionpack/lib/sprockets/helpers')
-rw-r--r-- | actionpack/lib/sprockets/helpers/rails_helper.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 690c71b472..a1e504be25 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -157,18 +157,25 @@ module Sprockets end def rewrite_extension(source, dir, ext) - source_ext = File.extname(source) - if ext && source_ext != ".#{ext}" - if !source_ext.empty? && (asset = asset_environment[source]) && - asset.pathname.to_s =~ /#{source}\Z/ - source - else - "#{source}.#{ext}" - end - else + source_ext = File.extname(source)[1..-1] + + if !ext || ext == source_ext + source + elsif source_ext.blank? + "#{source}.#{ext}" + elsif exact_match_present?(source) source + else + "#{source}.#{ext}" end end + + def exact_match_present?(source) + pathname = asset_environment.resolve(source) + pathname.to_s =~ /#{Regexp.escape(source)}\Z/ + rescue Sprockets::FileNotFound + false + end end end end |