Unquote and unescape Content-Type: charset [RFC7230]
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 83/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ruby
- 领域
- networking
调研方向
从 issue 中所示的 lib/net/http/header.rb 参数解析代码开始,然后针对包含带引号 charset 的 response 运行提供的 Net::HTTP 复现。验证带引号和经过转义的 Content-Type 参数能够生成有效的 encoding 名称,并且 request 能够成功完成;如果 repository 现有的测试提供了合适的位置,则添加回归覆盖。
由索引模型根据 Issue 内容生成。
描述
uri = URI('http://127.0.0.1:8080')
http = Net::HTTP.new(uri.hostname, uri.port)
http.response_body_encoding = true
http.send_request('GET', uri.request_uri)
/opt/homebrew/lib/ruby/gems/4.0.0/gems/net-http-0.9.1/lib/net/http/response.rb:381:in 'String#force_encoding': unknown encoding name - "UTF-8" (ArgumentError)
@body.force_encoding(enc) if enc
from /opt/homebrew/lib/ruby/gems/4.0.0/gems/net-http-0.9.1/lib/net/http/response.rb:381:in 'Net::HTTPResponse#read_body'
$ curl -I http://127.0.0.1:8080/
Content-Type: text/html; charset="UTF-8"
Server: WEBrick/1.9.2 (Ruby/4.0.1/2026-01-13)
$ open https://www.rfc-editor.org/rfc/rfc7230#section-3.2.6
[3.2.6](https://www.rfc-editor.org/rfc/rfc7230#section-3.2.6). Field Value Components
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
$ git diff
diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb
index 797a3be..fe026ae 100644
--- a/lib/net/http/header.rb
+++ b/lib/net/http/header.rb
@@ -762,3 +762,3 @@ module Net::HTTPHeader
k, v = *param.split('=', 2)
- result[k.strip] = v.strip
+ result[k.strip] = v.strip.gsub(/\A"(.*?)(?<!\\)"\z/) { $1.gsub(/\\(.)/, '\1') }.strip
end
http.send_request('GET', uri.request_uri)
# #<Net::HTTPOK 200 OK readbody=true>
- 主要语言
- Ruby
- 星标
- 148
- 派生
- 95
- 平均合并
- 10 小时 54 分钟
- 30 天内合并 PR
- 4
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/net-http 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 5/5 一周以上 新手友好度 38/100
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 55/100
-
bug documentation
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
user-reported
难度 2/5 1-3 小时 新手友好度 85/100
Kong/developer.konghq.com#7316 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
TheOdinProject/curriculum#31408 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 74/100
bensheldon/good_job#1816 · 5 条评论 ·