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 摘要。