From d6059c2a9b0e152ea81cea2b769a29d10671074f Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Fri, 20 Apr 2012 15:42:10 +0200 Subject: [PATCH] fix issue #373 --- lib/locomotive/dragonfly.rb | 2 ++ .../lib/locomotive/liquid/filters/resize_spec.rb | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/locomotive/dragonfly.rb b/lib/locomotive/dragonfly.rb index 743cdba5..1487e634 100644 --- a/lib/locomotive/dragonfly.rb +++ b/lib/locomotive/dragonfly.rb @@ -7,6 +7,8 @@ module Locomotive if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset source = source['url'] if source.is_a?(Hash) + source.strip! + if source =~ /^http/ file = self.app.fetch_url(source) else diff --git a/spec/lib/locomotive/liquid/filters/resize_spec.rb b/spec/lib/locomotive/liquid/filters/resize_spec.rb index 8ef3097b..1b2056a8 100644 --- a/spec/lib/locomotive/liquid/filters/resize_spec.rb +++ b/spec/lib/locomotive/liquid/filters/resize_spec.rb @@ -17,13 +17,19 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse('{{ asset_url | resize: "40x30" }}') end - it 'should return the location of the resized image' do + it 'returns the location of the resized image' do @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ end - it 'should use the path in the public folder to generate a location' do + it 'uses the path in the public folder to generate a location' do @template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30') end + + it 'accepts strings with leading and trailing empty characters' do + @context['asset_url'] = " \t #{@context['asset_url']} \n\n " + @template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30') + end + end context 'when a theme asset is given' do @@ -31,11 +37,11 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse("{{ theme_asset | resize: '300x400' }}") end - it 'should return the location of the resized image' do + it 'returns the location of the resized image' do @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ end - it 'should use the path of the theme asset to generate a location' do + it 'uses the path of the theme asset to generate a location' do @template.render(@context).should == Locomotive::Dragonfly.resize_url(@theme_asset_path, '300x400') end end @@ -45,7 +51,7 @@ describe Locomotive::Liquid::Filters::Resize do @template = Liquid::Template.parse('{{ asset | resize: }}') end - it 'should return a liquid error' do + it 'returns a liquid error' do @template.render(@context).should include 'Liquid error: wrong number of arguments' end end