From 0f76ab666a6d70beb67499c996d759c8440f008a Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 29 May 2015 14:18:41 -0400 Subject: [PATCH] Do not gzip assets that are already gzipped --- lib/sprockets/asset.rb | 4 +++- lib/sprockets/static_asset.rb | 4 +++- test/fixtures/asset/archive.tar.gz | Bin 0 -> 170 bytes test/test_asset.rb | 13 +++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/asset/archive.tar.gz 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 0000000000000000000000000000000000000000..7bed8339682215a6b950fa424e3a6efb2eca3c79 GIT binary patch literal 170 zcmb2|=3tn*DkGGE`RzqVzC#KEtq<4PvZ`NbWU}QqHQS}+Xi`<(xmIu138%{vkN@jd z%;uD=P|W?_{yFcmj)#lY^DDN0XC%FuA-uFV+t;#3Om){)Kl4+%JFgsmIm20N^_S}+ z$#u5j$J!Pao&VC8{;$K}tNoE3=cb?fZ6EOOaCG$R`{#abzgFHm$#vVzpP&Ezo)C8b U9wP%1I8dF}rnllhg9ZZw02qKz!T