`MaskedInput` validation passes with required `X` places left empty

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
frontend

調査の方向性

MaskedInput と、issue で直接名指しされている _Template.validate から始めてください。3 つのウィジェットのスニペットで再現し、3 つのケースすべてが無効になるべきであることを確認します。chr(0) によるパディングが値の末尾で [^ ] の一致を通してしまう一方、途中のスペースは失敗することを比較し、既存のマスク入力テストで期待される検証動作を確認してください。空の必須 X の位置が、途中だけでなく末尾でも失敗することが完了条件です。すべてが X のテンプレートと混在したテンプレートの両方を対象にした回帰テストを追加してください。

索引モデルが issue の本文から書いたものです。

説明

Hi! I hit this while writing generated tests against Textual's widgets.

The docs list X ([^ ]) as a required template character. But a MaskedInput validates as valid when its X places at the end are empty, and so does one whose template is only X places with no value at all. A 9 place in the same position is reported as missing, as expected.

import asyncio

from textual.app import App, ComposeResult
from textual.widgets import MaskedInput

class MaskedApp(App):
    def compose(self) -> ComposeResult:
        yield MaskedInput("XXX", id="code")
        yield MaskedInput("99-XX", value="12-", id="mixed")
        yield MaskedInput("99-99", value="12-", id="digits")

async def main():
    app = MaskedApp()
    async with app.run_test():
        for masked in app.query(MaskedInput):
            result = masked.validate(masked.value)
            print(
                f"template={masked.template!r} value={masked.value!r}: "
                f"is_valid={result.is_valid}"
            )

asyncio.run(main())

Output on Textual 8.2.7, and the same on main at 5e5b7ef:

template='XXX' value='': is_valid=True
template='99-XX' value='12-': is_valid=True
template='99-99' value='12-': is_valid=False

Expected: False for all three. An empty X place in the middle of the value (12- 4 on 99-XX) already fails, because it holds a space.

_Template.validate pads the value to the template's length with chr(0) before checking it, and [^ ] matches chr(0). So padded X places pass, while every other required pattern rejects chr(0). Padding with spaces, which is what an empty place holds inside the value, would make the end of the value behave like the middle. I'm happy to send a PR.

主要言語
Python
スター
37.7k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

Textualize/textual のほかの issue

Textualize/textual の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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