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 16, 2022
1 parent 46cdf53 commit 156cfdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/pdfkit/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def shell_safe_url
end

def url_needs_escaping?
URI::DEFAULT_PARSER.unescape(@source) == @source
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 excape part of it" do
source = PDFKit::Source.new("https://www.google.com/search?q='%20 sleep'")
expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='%2520%20sleep'\""
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 156cfdc

Please sign in to comment.