Repository navigation
Match all HTML case-insensitive attribute values without case sensitivity - #329
Conversation
| `type` values that contain a newline. | ||
| - **FIX**: Match the values of every attribute that the HTML specification lists as case insensitive (`rel`, | ||
| `method`, `lang`, `dir`, ...) without case sensitivity on HTML elements in HTML documents, not just `type`. SVG | ||
| and MathML elements are matched case sensitively. |
There was a problem hiding this comment.
Please add "MathML" to en-custom.txt in sorted order so that the spell checker will not fail.
There was a problem hiding this comment.
The changelog entry no longer mentions MathML: in c694e30 it says "Non-HTML elements are matched case sensitively" instead, so there is nothing to add to en-custom.txt. The documents spelling job passes on the latest commit. The two regressions @MaciejZet reported are fixed in 5da4f5e, with tests.
|
Two regressions on c10b4da, both confirmed against Chrome 155: from bs4 import BeautifulSoup
import soupsieve as sv
soup = BeautifulSoup('<a id="x" rel="ſtylesheet"></a>', 'html5lib')
print(bool(sv.select('[rel~="stylesheet"]', soup)))
# PR: True; expected: False
soup = BeautifulSoup('<r><a id="x" rel="pre match"/></r>', 'xml')
print(bool(sv.select('[rel*="match"]', soup)))
# PR: False; expected: TrueBoth cases return the expected result on base b4f750c and main 72b2600. All 18 local functional test runs passed on macOS across Python 3.11–3.15.0rc1 and the stdlib-only configuration; Ruff and mypy also passed. These two cases need regression coverage. |
|
@MaciejZet these are good points and they'll need to be resolved before we can merge. |
|
Addressed both reported regressions in 5da4f5e. The HTML-only default now uses ASCII case-insensitive matching, so |
…-attributes # Conflicts: # docs/src/markdown/about/changelog.md
|
Thanks! I'll take a look at this sometime today. |
|
@gir-bot lgtm |
Only
typegets case-insensitive attribute value matching in HTML today (from #7, which assumed it was the only attribute with that convention). The HTML specification lists 46 attributes whose values are matched ASCII case-insensitively by attribute selectors on HTML elements in HTML documents,typebeing one of them (Case-sensitivity of selectors):rel,method,lang,dir,align,target,media, and so on.The same section limits this to HTML elements. In Chrome,
<svg><feTurbulence type="fractalNoise">is not matched by[type="fractalnoise"]and<svg><a rel="NoFollow">is not matched by[rel="nofollow"]. Soup Sieve currently applies thetyperule to SVG elements too.Changes:
css_parser.py: thetypecheck becomes a lookup inHTML_CASE_INSENSITIVE_ATTRIBUTES, which is the list from the spec. The compiled patterns are unchanged: a case-insensitive one, plus the case-sensitivexml_type_patternas before.css_match.py:match_attributesuses the case-sensitive pattern for XML documents (as before) and also for non-HTML elements (not self.is_html_tag(el)). Withhtml.parserandlxml, which don't provide namespaces, every element still counts as HTML, so their behavior only changes by the added attribute names.I compared the results with Chrome's
querySelectorAllon the same markup. Withhtml5libthey match for[type="checkbox"],[type="fractalnoise"],[rel="nofollow"],[method="post"],[lang="en-US"],[dir="rtl"]and[title="abc"](not in the list, so it stays case-sensitive).Tests:
test_attribute_html_case_insensitive_valuesandtest_attribute_html_case_insensitive_values_foreignintests/test_level2/test_attribute.pyfail without the change. The existingtypetests for HTML, XML and XHTML pass unchanged. The full suite passes (434 passed, 1 skipped), along withruff check .andmypy. I added a changelog entry under Unreleased.