Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#163 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-hyper/uritemplate のほかの issue

python-hyper/uritemplate の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。