Skip to content

Commit

Permalink
modify url_needs_escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
KWkyle committed Sep 26, 2022
1 parent 46cdf53 commit 8e759c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pdfkit/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def shell_safe_url
end

def url_needs_escaping?
URI::DEFAULT_PARSER.unescape(@source) == @source
URI::DEFAULT_PARSER.escape(URI::DEFAULT_PARSER.unescape(@source)) != @source
end
end
end
5 changes: 5 additions & 0 deletions spec/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
end

it "URI escapes source URI only escape part of it" do
source = PDFKit::Source.new("https://www.google.com/search?q='%20 sleep 5'")
expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='%2520%20sleep%205'\""
end

it "does not URI escape previously escaped source URLs" do
source = PDFKit::Source.new("https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'")
expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
Expand Down

0 comments on commit 8e759c7

Please sign in to comment.