From 4f83a368aa4f45c94552fd6a18f5f13c675811b5 Mon Sep 17 00:00:00 2001 From: Ricardo Nacif Date: Wed, 29 Jul 2015 13:00:05 -0700 Subject: [PATCH] fixing url with ampersand by scaping them --- lib/imgkit/source.rb | 17 ++++++++++++++--- spec/imgkit_spec.rb | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/imgkit/source.rb b/lib/imgkit/source.rb index 9340036..eaaf0d6 100644 --- a/lib/imgkit/source.rb +++ b/lib/imgkit/source.rb @@ -19,9 +19,20 @@ def html? end def to_s - file? ? @source.path : @source + if file? + @source.path + elsif url? + escaped_url + else + @source + end + end + + private + + def escaped_url + @source.gsub '&', '\\\\&' end - end -end +end \ No newline at end of file diff --git a/spec/imgkit_spec.rb b/spec/imgkit_spec.rb index 575887d..fce1550 100644 --- a/spec/imgkit_spec.rb +++ b/spec/imgkit_spec.rb @@ -14,6 +14,12 @@ imgkit.source.to_s.should == 'http://google.com' end + it "should accept a URL as the source with ampersand and scape the ampersand" do + imgkit = IMGKit.new('http://google.com?something=1&anotherthing=2') + imgkit.source.should be_url + imgkit.source.to_s.should == 'http://google.com?something=1\&anotherthing=2' + end + it "should accept a File as the source" do file_path = File.join(SPEC_ROOT,'fixtures','example.html') imgkit = IMGKit.new(File.new(file_path))