Skip to content

Commit 2d90e9b

Browse files
authored
url_encode: use CGI.escapeURIComponent (#23)
Ref: ruby/cgi#26 This native implementation is much faster and available in `cgi 0.3.3`.
1 parent a3492c4 commit 2d90e9b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- id: versions
1212
run: |
13-
versions=$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/cruby.json' | jq -c '. + ["2.5"]')
13+
versions=$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/cruby.json')
1414
echo "::set-output name=value::${versions}"
1515
test:
1616
needs: ruby-versions

erb.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
2727
spec.executables = ['erb']
2828
spec.require_paths = ['lib']
2929

30-
spec.add_dependency 'cgi'
30+
spec.required_ruby_version = ">= 2.7.0"
31+
32+
spec.add_dependency 'cgi', '>= 0.3.3'
3133
end

lib/erb.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,7 @@ def html_escape(s)
10191019
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
10201020
#
10211021
def url_encode(s)
1022-
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
1023-
sprintf("%%%02X", m.unpack1("C"))
1024-
}
1022+
CGI.escapeURIComponent(s.to_s)
10251023
end
10261024
alias u url_encode
10271025
module_function :u

0 commit comments

Comments
 (0)