parse_header_links drops parameters when a value contains '=' or a quoted ';'
还没有人认领这个 Issue。
评估
调研方向
从 src/requests/utils.py 中的 parse_header_links 开始,检查参数解析。为包含 = 的值和带引号且包含 ; 的值添加回归测试,然后运行此实用程序的相关测试。两种复现情况都保留所有参数及其完整值,即为完成。
由索引模型根据 Issue 内容生成。
描述
Summary
requests.utils.parse_header_links silently drops Link header parameters in two cases.
1. Parameter value containing =
In src/requests/utils.py, key, value = param.split("=") raises ValueError when the value contains =. The except ValueError: break then discards every remaining parameter.
2. ; inside a quoted value
params.split(";") ignores quoting, so a quoted value containing ; is truncated and the rest is lost.
Repro
from requests.utils import parse_header_links as p
p('<https://a/b>; rel="next"; title="x=y"; type="t"')
# actual: [{'url': 'https://a/b', 'rel': 'next'}] # title and type missing
# expected: [{'url': 'https://a/b', 'rel': 'next', 'title': 'x=y', 'type': 't'}]
p('<https://a/b>; title="a;b"; rel=next')
# actual: [{'url': 'https://a/b', 'title': 'a'}] # rel missing, title truncated
# expected: [{'url': 'https://a/b', 'title': 'a;b', 'rel': 'next'}]
Suggested fix
Use param.split("=", 1) and split parameters in a quote-aware way. I'm happy to open a PR with tests if this is welcome.
Checked on current main. I searched existing issues (#2250, #2707, #7177 are related to other cases) and found none covering this.
- 主要语言
- Python
- 星标
- 54.7k
- 派生
- 10.8k
- 平均合并
- 18 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
psf/requests 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
-
get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)可能已有人在做 @suyashgitt 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"未关闭
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
OCA/account-invoicing#2529 ·
维护者通常 1 天内回复
-
area/ci
难度 1/5 1 小时以内 新手友好度 62/100
维护者通常 1 天内回复
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster text未关闭bug imagen skills
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Email validation accepts a trailing newline可能已有人在做 @marcello-pichini 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复