From 7c31ed22a237b9b0f9e0a348a482fa1ce0754d3b Mon Sep 17 00:00:00 2001 From: BooGu <144680841+boogu2005@users.noreply.github.com> Date: Sun, 1 Nov 2026 23:03:15 +0800 Subject: [PATCH] fix: match checked input types without ASCII case sensitivity --- cssselect/xpath.py | 6 +++++- tests/test_cssselect.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cssselect/xpath.py b/cssselect/xpath.py index c46c500..6f5423c 100644 --- a/cssselect/xpath.py +++ b/cssselect/xpath.py @@ -929,11 +929,15 @@ def __init__(self, xhtml: bool = False) -> None: def xpath_checked_pseudo(self, xpath: XPathExpr) -> XPathExpr: # FIXME: is this really all the elements? + type_attr = ( + "translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', " + "'abcdefghijklmnopqrstuvwxyz')" + ) return xpath.add_condition( "(@selected and name(.) = 'option') or " "(@checked " "and (name(.) = 'input' or name(.) = 'command')" - "and (@type = 'checkbox' or @type = 'radio'))" + f"and ({type_attr} = 'checkbox' or {type_attr} = 'radio'))" ) def xpath_lang_function(self, xpath: XPathExpr, function: Function) -> XPathExpr: diff --git a/tests/test_cssselect.py b/tests/test_cssselect.py index 266bbca..517ea3b 100644 --- a/tests/test_cssselect.py +++ b/tests/test_cssselect.py @@ -1419,6 +1419,38 @@ def langid(selector: str) -> list[str]: assert HTMLTranslator(xhtml=True).css_to_xpath("A") == ("descendant-or-self::A") assert HTMLTranslator().css_to_xpath("A") == ("descendant-or-self::a") + def test_html_checked_type_case(self) -> None: + document = etree.fromstring( + '