`WEBrick::HTTPUtils.escape(nil)` raises a confusing exception
还没有人认领这个 Issue。
评估
调研方向
从 lib/webrick/httputils.rb 中 HTTPUtils.escape 和 _escape 附近开始,然后将报告的 nil 行为与 escape_form(nil) 进行比较。对照 CGI.escape、URI.encode_www_form_component 和 ERB::Util.url_encode 检查提出的三种结果;完成此项工作需要 maintainer 决定预期的 nil 行为,并提供相应的覆盖率。
由索引模型根据 Issue 内容生成。
描述
% 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.
- 主要语言
- Ruby
- 星标
- 327
- 派生
- 113
- 平均合并
- 4 小时 2 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/webrick 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 45/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
riscv/riscv-unified-db#2626 ·
-
Component: GLib
难度 2/5 1-3 小时 新手友好度 70/100
-
ds-drift
难度 2/5 1-3 小时 新手友好度 70/100
we-promise/sure#3693 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
simp/pupmod-simp-simp#395 ·