Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing url with ampersand by scaping them #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/imgkit/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/imgkit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down