Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Prefix modifier crashes on non-string values; reserved expansion stops encoding once the value contains a percent-escape

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

还没有人认领这个 Issue。

评估

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

调研方向

从 uritemplate/variable.py 开始,issue 指出了前缀处理和保留扩展的引用处理路径。阅读 RFC 6570 的相关章节,并找到覆盖 {var:N}、{+var} 和 {#var} 的测试。为非字符串前缀值以及与不安全字符混合的百分号转义添加回归测试;两个情况都按照 RFC 展开即为完成。

由索引模型根据 Issue 内容生成。

描述

Two related problems in uritemplate/variable.py, reproduced on 4.2.0 (main 8e46228).

1. {var:N} with an int or float value raises TypeError
>>> from uritemplate import expand
>>> expand("{a:1}", {"a": 12})
TypeError: 'int' object is not subscriptable
>>> expand("{a}", {"a": 12})
'12'

Non-string scalars are accepted everywhere else (they are converted with str() in Operator.quote), but the prefix is applied before that conversion: value = value[:prefix] if prefix else value. Converting first (str(value)[:prefix]) fixes it; RFC 6570 §2.4.1 defines the prefix on the string form of the value.

2. Reserved (+) and fragment (#) expansion leave unsafe characters unencoded if the value contains any %XX
>>> from uritemplate import expand
>>> expand("{+a}", {"a": "a b"})
'a%20b'
>>> expand("{+a}", {"a": "a b%41"})
'a b%41'        # expected 'a%20b%41'

Operator._only_quote_unquoted_characters returns the value unchanged whenever unquote(value) != value, so one pre-existing percent-escape disables encoding for the whole string, including the space. RFC 6570 §3.2.3 says reserved expansion keeps existing pct-encoded triplets and encodes everything else that is not in reserved/unreserved; the check needs to be per character (or per triplet), not per string.

Happy to send a PR with tests for both if you would take one.

主要语言
Python
星标
246
派生
41
平均合并
8 小时 20 分钟
30 天内合并 PR
3

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

python-hyper/uritemplate 的其他 Issue

查看 python-hyper/uritemplate 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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