aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-10-25 18:39:56 +0200
committergit <svn-admin@ruby-lang.org>2022-10-25 16:40:05 +0000
commit217fdbf9aa6dd850eace9f10c9a74bcec8b510e2 (patch)
tree06bdcd49fca3f87139005cec4dc905681b12fb50
parentb7644a231100b1e1b70af528f9629d2e39572087 (diff)
downloadruby-217fdbf9aa6dd850eace9f10c9a74bcec8b510e2.tar.gz
[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
-rw-r--r--lib/erb.gemspec4
-rw-r--r--lib/erb.rb4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/erb.gemspec b/lib/erb.gemspec
index 43ffc89c69..e89a358f8a 100644
--- a/lib/erb.gemspec
+++ b/lib/erb.gemspec
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
spec.executables = ['erb']
spec.require_paths = ['lib']
- spec.add_dependency 'cgi'
+ spec.required_ruby_version = ">= 2.7.0"
+
+ spec.add_dependency 'cgi', '>= 0.3.3'
end
diff --git a/lib/erb.rb b/lib/erb.rb
index 0e42425a60..962eeb6963 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -1019,9 +1019,7 @@ class ERB
# 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