Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate ids #4032

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `SelectionList` option IDs are usable as soon as the widget is instantiated https://github.com/Textualize/textual/issues/3903
- Fix issue with `Strip.crop` when crop window start aligned with strip end https://github.com/Textualize/textual/pull/3998
- Fixed Strip.crop_extend https://github.com/Textualize/textual/pull/4011
- ID and class validation was too lenient https://github.com/Textualize/textual/issues/3954


## [0.47.1] - 2023-01-05
Expand Down
2 changes: 1 addition & 1 deletion src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

from typing_extensions import Literal

_re_identifier = re.compile(IDENTIFIER)
_re_identifier = re.compile(f"^{IDENTIFIER}$")
rodrigogiraoserrao marked this conversation as resolved.
Show resolved Hide resolved


WalkMethod: TypeAlias = Literal["depth", "breadth"]
Expand Down
21 changes: 21 additions & 0 deletions tests/test_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,24 @@ def test_walk_children_with_self_breadth(search):
]

assert children == ["f", "e", "d", "c", "b", "a"]


@pytest.mark.parametrize(
"identifier",
[
" bad",
" terrible ",
"worse! ",
"&ampersand",
"amper&sand",
"ampersand&",
"2_leading_digits",
"água", # water
"cão", # dog
"@'/.23",
],
)
def test_id_validation(identifier: str):
"""Regression tests for https://github.com/Textualize/textual/issues/3954."""
with pytest.raises(BadIdentifier):
DOMNode(id=identifier)
Loading