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
-
Python Volcengine provider returns failures instead of raising them可能已有人在做 @Ricardo-M-L 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 79/100
agent-infra/sandbox#248 ·
-
Textractor leaves empty temporary files when remote retrieval fails可能已有人在做 @HuaTNA 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
test(bm_generation): pin the learning parameters and CPU sync shortcut可能已有人在做 @iloveeyjafjalla 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
qboson/kaiwu-pytorch-plugin#1341 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
elder-plinius/V3R1T4S#625 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆