diff --git a/lib/sprockets/asset.rb b/lib/sprockets/asset.rb index cabf717c3..93163ca86 100644 --- a/lib/sprockets/asset.rb +++ b/lib/sprockets/asset.rb @@ -139,7 +139,9 @@ def stale?(environment) # Save asset to disk. def write_to(filename, options = {}) # Gzip contents if filename has '.gz' - options[:compress] ||= File.extname(filename) == '.gz' + unless options.key?(:compress) + options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz' + end FileUtils.mkdir_p File.dirname(filename) diff --git a/lib/sprockets/static_asset.rb b/lib/sprockets/static_asset.rb index 70533bbec..7ea0add2e 100644 --- a/lib/sprockets/static_asset.rb +++ b/lib/sprockets/static_asset.rb @@ -21,7 +21,9 @@ def to_path # Save asset to disk. def write_to(filename, options = {}) # Gzip contents if filename has '.gz' - options[:compress] ||= File.extname(filename) == '.gz' + unless options.key?(:compress) + options[:compress] = File.extname(filename) == '.gz' && File.extname(logical_path) != '.gz' + end FileUtils.mkdir_p File.dirname(filename) diff --git a/test/fixtures/asset/archive.tar.gz b/test/fixtures/asset/archive.tar.gz new file mode 100644 index 000000000..7bed83396 Binary files /dev/null and b/test/fixtures/asset/archive.tar.gz differ diff --git a/test/test_asset.rb b/test/test_asset.rb index 0a6a118f3..8155d3e4c 100644 --- a/test/test_asset.rb +++ b/test/test_asset.rb @@ -77,6 +77,19 @@ def self.test(name, &block) assert !File.exist?(target) end end + + test "do not gzip assets that are already gzipped" do + @asset = @env.find_asset('archive.tar.gz') + target = fixture_path('asset/tmp.tar.gz') + begin + @asset.write_to(target) + assert File.exist?(target) + assert_equal Digest::MD5.hexdigest(@asset.to_s), Digest::MD5.hexdigest(File.read(target)) + ensure + FileUtils.rm(target) if File.exist?(target) + assert !File.exist?(target) + end + end end module FreshnessTests