parse_header_links drops parameters when a value contains '=' or a quoted ';'

未关闭 适合新手
#7,643 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api, backend

调研方向

从 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

psf/requests 的其他 Issue

查看 psf/requests 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。