Skip to content

Commit

Permalink
url_encode: use CGI.escapeURIComponent
Browse files Browse the repository at this point in the history
Ref: ruby/cgi#26

This native implementation is much faster
and available in `cgi 0.3.3`.
  • Loading branch information
byroot committed Oct 25, 2022
1 parent a3492c4 commit 83ea8c8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion erb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
spec.executables = ['erb']
spec.require_paths = ['lib']

spec.add_dependency 'cgi'
spec.add_dependency 'cgi', '>= 0.3.3'
end
4 changes: 1 addition & 3 deletions lib/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,7 @@ def html_escape(s)
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
#
def url_encode(s)
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
sprintf("%%%02X", m.unpack1("C"))
}
CGI.escapeURIComponent(s.to_s)
end
alias u url_encode
module_function :u
Expand Down

0 comments on commit 83ea8c8

Please sign in to comment.