`MaskedInput` validation passes with required `X` places left empty
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start from MaskedInput and its _Template.validate, which the issue names directly; reproduce with the three-widget snippet to confirm all three cases should be invalid. Compare how padding with chr(0) lets [^ ] matches through at the end of the value, while a space in the middle fails, and check the existing masked-input tests for the expected validation behavior. Done means empty required X places fail at the end as well as in the middle, with a regression test covering both the all-X and mixed templates.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day