[ruby/erb] url_encode: use CGI.escapeURIComponent
(https://github.com/ruby/erb/pull/23) Ref: https://github.com/ruby/cgi/pull/26 This native implementation is much faster and available in `cgi 0.3.3`. https://github.com/ruby/erb/commit/2d90e9b010
This commit is contained in:
parent
b7644a2311
commit
217fdbf9aa
@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
|
|||||||
spec.executables = ['erb']
|
spec.executables = ['erb']
|
||||||
spec.require_paths = ['lib']
|
spec.require_paths = ['lib']
|
||||||
|
|
||||||
spec.add_dependency 'cgi'
|
spec.required_ruby_version = ">= 2.7.0"
|
||||||
|
|
||||||
|
spec.add_dependency 'cgi', '>= 0.3.3'
|
||||||
end
|
end
|
||||||
|
@ -1019,9 +1019,7 @@ class ERB
|
|||||||
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
||||||
#
|
#
|
||||||
def url_encode(s)
|
def url_encode(s)
|
||||||
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
|
CGI.escapeURIComponent(s.to_s)
|
||||||
sprintf("%%%02X", m.unpack1("C"))
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
alias u url_encode
|
alias u url_encode
|
||||||
module_function :u
|
module_function :u
|
||||||
|
Loading…
x
Reference in New Issue
Block a user