`WEBrick::HTTPUtils.escape(nil)` raises a confusing exception
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start in lib/webrick/httputils.rb around HTTPUtils.escape and _escape, then compare the reported nil behavior with escape_form(nil). Review the three proposed outcomes against CGI.escape, URI.encode_www_form_component, and ERB::Util.url_encode; done requires a maintainer decision on the intended nil behavior and corresponding coverage.
Written by the indexing model from the issue text.
Description
% irb
> RUBY_VERSION
=> "3.1.2"
> require 'webrick'
> WEBrick::HTTPUtils.escape(nil)
/Users/katsuhiko.yoshida/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/httputils.rb:444:in `_escape': undefined method `b' for nil:NilClass (NoMethodError)
str = str.b
^^
(omit)
%irb
> RUBY_VERSION
=> "2.7.6"
> WEBrick::HTTPUtils.escape(nil)
Traceback (most recent call last):
7: from /Users/katsuhiko.yoshida/.rbenv/versions/2.7.6/bin/irb:23:in `<main>'
6: from /Users/katsuhiko.yoshida/.rbenv/versions/2.7.6/bin/irb:23:in `load'
5: from /Users/katsuhiko.yoshida/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
4: from (irb):2
3: from (irb):3:in `rescue in irb_binding'
2: from /Users/katsuhiko.yoshida/.rbenv/versions/2.7.6/lib/ruby/2.7.0/webrick/httputils.rb:467:in `escape'
1: from /Users/katsuhiko.yoshida/.rbenv/versions/2.7.6/lib/ruby/2.7.0/webrick/httputils.rb:443:in `_escape'
NoMethodError (undefined method `b' for nil:NilClass)
WEBrick::HTTPUtils.escape_form(nil) is also the same. If the exception was raised in complex situations (e.g. in third party library), it will be difficult to determine the cause (parameter is nil).
My suggestions are following.
- Raises a builtin exception
CGI.escapeis this behavior (raises aTypeError)
- Raises a custom exception
- Like a
EscapeError
- Like a
- Returns
""URI.encode_www_form_componentandERB::Util.url_encodeare this behavior- But, BREAKING CHANGE (doesn't stop)
Thank you for your great work.
- Dominant language
- Ruby
- Stars
- 328
- Forks
- 114
- Avg merge
- 1h 15m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/webrick
-
Retire superfluous quoting of Content-Type: charset [RFC7230]Possibly taken @jeremyevans claimed this 62 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
CGI script using LF line breaks in headers causes errorPossibly taken @paulownia claimed this 603 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Similar issues
-
needs verification
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 13 days
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
betagouv/conseillers-entreprises#4808 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
yosiat/panko_serializer#250 ·