Prefix modifier crashes on non-string values; reserved expansion stops encoding once the value contains a percent-escape
还没有人认领这个 Issue。
评估
调研方向
从 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-hyper/uritemplate 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
python-hyper/uritemplate#164 ·
-
难度 3/5 1-2 天 新手友好度 35/100
python-hyper/uritemplate#51 ·
-
难度 5/5 一周以上 新手友好度 25/100
python-hyper/uritemplate#34 · 4 条评论 ·
-
Provide an API for validating URI Templates可能已有人在做 @sigmavirus24 于 3380 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 35/100
python-hyper/uritemplate#33 · 9 条评论 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 45/100
python-hyper/uritemplate#15 ·
查看 python-hyper/uritemplate 的全部 Issue
相似的 Issue
-
[Resource]: Lore未关闭resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 88/100
hesreallyhim/awesome-claude-code#3234 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openminion/openminion#376 ·
维护者通常 1 天内回复
-
Type: ☹︎ Bug
难度 2/5 1-3 小时 新手友好度 78/100
posit-dev/great-tables#1028 ·
维护者通常 1 天内回复
-
integration: apple_tv
难度 2/5 1-3 小时 新手友好度 78/100
home-assistant/core#188282 · 1 条评论 ·
维护者通常 1 天内回复
-
A "since" range is worded as a career: "the past two seasons" says "regular season career (2025 on)"未关闭P4: low
难度 2/5 1-3 小时 新手友好度 65/100
jeffknupp/association#538 ·