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))