From 956fd8b11448224c00d8e624c5cd9c61452087ff Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Sun, 19 Feb 2023 09:46:47 +0000 Subject: [PATCH 1/6] All numbers in continued selectors See #1836. --- src/textual/css/tokenize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/css/tokenize.py b/src/textual/css/tokenize.py index 2a8677f68..b2cd3d30e 100644 --- a/src/textual/css/tokenize.py +++ b/src/textual/css/tokenize.py @@ -75,7 +75,7 @@ expect_selector_continue = Expect( selector_id=r"\#[a-zA-Z_\-][a-zA-Z0-9_\-]*", selector_class=r"\.[a-zA-Z_\-][a-zA-Z0-9_\-]*", selector_universal=r"\*", - selector=r"[a-zA-Z_\-]+", + selector=IDENTIFIER, combinator_child=">", new_selector=r",", declaration_set_start=r"\{", From b340c27d6ac78eca5e2d5b64d4906a2289ac374c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Sun, 19 Feb 2023 09:49:40 +0000 Subject: [PATCH 2/6] Update the CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98fdac88e..7727141ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- Numbers in a descendant-combined selector no longer cause an error https://github.com/Textualize/textual/issues/1836 + ## [0.11.1] - 2023-02-17 ### Fixed From f785a5176993fb39f47d060afd36128a6f7d7689 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 10:08:02 +0000 Subject: [PATCH 3/6] Add combined type CSS parsing tests --- tests/css/test_parse.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/css/test_parse.py b/tests/css/test_parse.py index 727d45af4..00cd8d52d 100644 --- a/tests/css/test_parse.py +++ b/tests/css/test_parse.py @@ -8,7 +8,7 @@ from textual.css.parse import substitute_references from textual.css.scalar import Scalar, Unit from textual.css.stylesheet import Stylesheet, StylesheetParseError from textual.css.tokenize import tokenize -from textual.css.tokenizer import ReferencedBy, Token +from textual.css.tokenizer import ReferencedBy, Token, TokenError from textual.css.transition import Transition from textual.geometry import Spacing from textual.layouts.vertical import VerticalLayout @@ -1189,3 +1189,40 @@ class TestParseTextAlign: stylesheet = Stylesheet() stylesheet.add_source(css) assert stylesheet.rules[0].styles.text_align == "start" + + +class TestTypeNames: + def test_type_no_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("TestType {}") + assert len(stylesheet.rules) == 1 + + def test_type_with_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("TestType1 {}") + assert len(stylesheet.rules) == 1 + + def test_type_starts_with_number(self): + stylesheet = Stylesheet() + stylesheet.add_source("1TestType {}") + with pytest.raises(TokenError): + stylesheet.parse() + + def test_combined_type_no_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} TestType {{}}") + assert len(stylesheet.rules) == 1 + + def test_combined_type_with_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} TestType1 {{}}") + assert len(stylesheet.rules) == 1 + + def test_combined_type_starts_with_number(self): + for seperator in " >,": + stylesheet = Stylesheet() + stylesheet.add_source(f"StartType {seperator} 1TestType {{}}") + with pytest.raises(TokenError): + stylesheet.parse() From 8ec13c3aba85866505abdaf15a4eb55ec46f1e5a Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 21:24:48 +0000 Subject: [PATCH 4/6] Fix variable name typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> --- tests/css/test_parse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/css/test_parse.py b/tests/css/test_parse.py index 00cd8d52d..e7f5f008b 100644 --- a/tests/css/test_parse.py +++ b/tests/css/test_parse.py @@ -1209,9 +1209,9 @@ class TestTypeNames: stylesheet.parse() def test_combined_type_no_number(self): - for seperator in " >,": + for separator in " >,": stylesheet = Stylesheet() - stylesheet.add_source(f"StartType {seperator} TestType {{}}") + stylesheet.add_source(f"StartType {separator} TestType {{}}") assert len(stylesheet.rules) == 1 def test_combined_type_with_number(self): From e8e00b1920e8618ea2dbaf8a998c55a8072e2985 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 21:25:03 +0000 Subject: [PATCH 5/6] Fix variable name typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> --- tests/css/test_parse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/css/test_parse.py b/tests/css/test_parse.py index e7f5f008b..27c2f6c60 100644 --- a/tests/css/test_parse.py +++ b/tests/css/test_parse.py @@ -1215,9 +1215,9 @@ class TestTypeNames: assert len(stylesheet.rules) == 1 def test_combined_type_with_number(self): - for seperator in " >,": + for separator in " >,": stylesheet = Stylesheet() - stylesheet.add_source(f"StartType {seperator} TestType1 {{}}") + stylesheet.add_source(f"StartType {separator} TestType1 {{}}") assert len(stylesheet.rules) == 1 def test_combined_type_starts_with_number(self): From e666ee7286f404236037adc53902160c85bb169c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 21:25:12 +0000 Subject: [PATCH 6/6] Fix variable name typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> --- tests/css/test_parse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/css/test_parse.py b/tests/css/test_parse.py index 27c2f6c60..49d3368d6 100644 --- a/tests/css/test_parse.py +++ b/tests/css/test_parse.py @@ -1221,8 +1221,8 @@ class TestTypeNames: assert len(stylesheet.rules) == 1 def test_combined_type_starts_with_number(self): - for seperator in " >,": + for separator in " >,": stylesheet = Stylesheet() - stylesheet.add_source(f"StartType {seperator} 1TestType {{}}") + stylesheet.add_source(f"StartType {separator} 1TestType {{}}") with pytest.raises(TokenError): stylesheet.parse()