`urllib.parse.parse_qsl` is accepting illegal characters
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
urllib.parse.parse_qsl parses query strings containing the ^ and ` characters, even though these are not valid query characters under RFC 3986.
Observed behaviour:
parse_qsl('foo=^', strict_parsing=True)
# [('foo', '^')]
parse_qsl('bar=`', strict_parsing=True)
# [('bar', '`')]
Expected behaviour:
According to RFC 3986, both ^ and ` must be percent-encoded if used in a URI. However, parse_qsl accepts them as-is without raising an error or warning. This could lead to applications treating invalid URLs as valid.
Detailed Code:
import sys
import platform
from urllib.parse import parse_qsl
def test_parse_qsl(query):
try:
result = parse_qsl(query, strict_parsing=True)
print(f"Query: {query!r} -> Parsed: {result}")
except ValueError as e:
print(f"Query: {query!r} -> Error: {e}")
# Test invalid query strings
test_parse_qsl("foo=^")
test_parse_qsl("bar=`")
# System information
os_name = platform.system()
os_release = platform.release()
python_impl = platform.python_implementation()
python_version = sys.version.split()[0]
python_compiler = platform.python_compiler()
print("\n--- System Information ---")
print(f"Python Implementation : {python_impl}")
print(f"Python Version : {python_version}")
print(f"Python Compiler : {python_compiler}")
print(f"Operating System : {os_name} {os_release}")
print(f"Machine : {platform.machine()}")
# Output:
# Query: 'foo=^' -> Parsed: [('foo', '^')]
# Query: 'bar=`' -> Parsed: [('bar', '`')]
# --- System Information ---
# Python Implementation : CPython
# Python Version : 3.13.1
# Python Compiler : GCC 14.2.0
# Operating System : Linux 4.14.174
# Machine : x86_64
References:
-
Section 2.2 Reserved Characters: https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
-
Section 2.3 Unreserved Characters: https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-138291
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 urllib.parse.parse_qsl 入口点开始,将其当前行为与 RFC 3986 第 2.2 和 2.3 节进行比较。检查现有的 urllib.parse 测试,然后验证包含未编码 ^ 和 ` 的查询是否按规范处理,并确保回归覆盖包含预期行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- networking
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100