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

Faraday is using a custom code to escape parameters instead of CGI.escape #1396

Open
rubyconvict opened this issue Feb 4, 2022 · 1 comment
Labels
info Generic question on how to use Faraday

Comments

@rubyconvict
Copy link

Basic Info

  • Faraday Version: all
  • Ruby Version: all

Issue description

Faraday is using a custom code to escape parameter characters instead of CGI.escape, written in core library (C) and known to be secure (less code and common sense)?

def escape(str)
str.to_s.gsub(ESCAPE_RE) do |match|
"%#{match.unpack('H2' * match.bytesize).join('%').upcase}"
end.gsub(' ', default_space_encoding)
end

Steps to reproduce

n/a

@iMacTia
Copy link
Member

iMacTia commented Feb 4, 2022

That's a great question, thanks for asking @rubyconvict.
I had to dig this one as that decision was taken 10 years ago!
From what I understand, CGI.escape works well with Ruby-backed backends (e.g. Rails), but it doesn't produce standard-compliant URLs. For example, spaces are encoded with a + as opposed to the standard %20.
This makes it hard to use when you call an API that is implemented in a different language/framework.
By implementing our own version of escape, we could customize its behaviour in ways that the standard CGI would not allow.

Now, this might well be outdated and maybe the CGI module does now allow for more customization.
I'd be open to hear more counterarguments if there's anyone familiar with this topic

@iMacTia iMacTia added the info Generic question on how to use Faraday label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info Generic question on how to use Faraday
Projects
None yet
Development

No branches or pull requests

2 participants