4.0
- BREAK: The contents of an HTML
templateare no longer treated as part of the document. Selectors do not
descend into atemplate, and elements inside one can't see beyond it, which also applies to pseudo-classes such
as:lang(),:disabled, and:default.selectandfilterwill still reach the contents of atemplatewhen
they are called on thetemplateitself, for examplesoup.template.select('p'). See the
FAQ for more information. - BREAK: The contents of an
iframeare no longer treated as a separate document, as they are not one in a
browser. Elements in aniframeare normal children, so:rootdoes not match them, and:default,
:indeterminate,:checked,:dir(),:lang(), and:read-writetreat them like any other element. Recent
versions ofhtml.parser,lxml, andhtml5liball escape the contents of aniframelike a browser does, so
this mostly affects XHTML, Python versions that still don't escape such content in their specifichtml.parser,
and elements added to aniframeby hand.:-soup-contains()now also includes the escaped text in aniframe.
See the FAQ for more information. - NEW: Update
:disabledand:enabledto treatoptionandoptgroupelements inside a disabledselectas
disabled, following a recent HTML specification update. - FIX: Fix the subsequent-sibling combinator and
:has(~ ...)never matching top level elements of a fragment
that has no root element, unless caching was disabled. - FIX:
:indeterminatenow treats a radio button group without a form as extending across the whole document
instead of the top level element that contains it, and it no longer ignores radio buttons at the top level. - FIX: Fix
:defaultto treat abuttonwith a missing or invalidtype, and aninputwithtype="image",
as submit buttons. - FIX: Fix
:in-rangeand:out-of-rangeraisingTypeErrorwhen the document contains aninputwithout a
typeattribute. - FIX:
:read-write(and:read-only) now treatcontenteditable="plaintext-only"elements as editing hosts and
match the editable elements inside an editing host, following the nearestcontenteditablestate. - FIX:
:read-write(and:read-only) now ignorecontenteditableon non-HTML elements, such as an SVG
foreignObject, as the attribute only applies to HTML elements. Such elements inherit the state of their parent. - FIX:
:checkednow only matches the last radio button with acheckedattribute in a radio button group, as
in a browser, where a group is the radio buttons with the samenameand form, including theformattribute.
:defaultstill matches all of them, and the contents of atemplateare unaffected as they are not connected. - FIX:
:dir()and:definedno longer affect the rest of the selector list they are in. Previously, a selector
list that used either of them could not have its combinators cross aniframe, ignored the specified namespaces,
and matched nothing in XML, not even the parts that didn't use them. They still do not match in XML, but
:not(:dir(ltr))and:not(:defined)now do. - FIX:
:defaultand:indeterminatenow honor theformattribute, which can associate a submit button or
radio button with a form it is not in, or leave it without a form. It is ignored in atemplate, as in the HTML
specification. Submit buttons outside of a form can now be its default button. - FIX:
:default,:checked, and:indeterminatenow handle a form inside a form like a browser. In HTML, a
browser ignores the nested form and takes its end tag for that of the parent, which matters for parsers that keep
the nested form, such ashtml.parser. In XHTML and in atemplate, nested forms are real forms. - FIX:
:checkednow matches theoptionthat a browser would select. Withoutmultiple, that is only the
lastoptionwith aselectedattribute in aselect, and if there are none and theselectshows a single
option, the firstoptionthat is not disabled.:defaultstill only considers theselectedattribute. - FIX: Fix
[attribute!=value]excluding values that only start with the specified value, and in XML documents,
typevalues that contain a newline. - FIX: Match the values of every attribute that the HTML specification lists as ASCII case insensitive (
rel,
method,lang,dir, ...) without ASCII case sensitivity on HTML elements in HTML documents, not justtype.
Non-HTML elements are matched case sensitively. - FIX:
:dir()now matches non-HTML elements, such as SVG and MathML, by the direction they inherit from their
parent (thedirattribute only applies to HTML elements), and HTML elements inside them, such as in an SVG
foreignObject, by the direction of their ancestors. - FIX: Fix
:dir()ignoring the value of aninputwithdir="auto"and a missing or emptytype. - FIX:
:dir()now uses a table generated from Unicode 18 instead ofunicodedata, so results no longer depend
on the Unicode version of the Python in use, and unassigned code points use their default direction. - FIX:
:dir()now uses the value of aninputwithdir="auto"whentypeishidden,password,submit,
reset, orbutton, as the HTML specification does. - FIX:
dir="auto"andbdinow analyze the text of non-HTML elements, such as SVG and MathML, and only ignore
HTML elements such asscript,style, andbdi. The text directly in aniframeis analyzed as well, and the
contents of atemplate, which are not part of the document, are not. - FIX:
:dir()no longer lets the contents of atemplateinherit direction from thetemplateor its
ancestors, as they are not part of the document. They are left to right unless they specify otherwise. - FIX:
:dir()now matches abdielement that is the root by its text instead of assuming left to right. - FIX:
:dir()now treats any element without a parent element as left to right, not just the root. Before,
all but the first top level element of a fragment parsed withhtml.parsernever matched. - FIX:
:dir()now accepts any identifier, as CSS requires, including escaped ones. Values other thanltrand
rtldo not match anything. - FIX: Respect namespaces provided by the parser when the root is not an HTML element, such as an
svgelement
extracted from anhtml5libdocument. Previously every element in such a tree was treated as an HTML element,
which affected namespace selectors, namespaced attributes, and HTML specific pseudo-classes. - FIX: Fix
:lang()treating an element with an emptylangorxml:langattribute as having the language of
a tagged ancestor. - FIX: Cache forms without a default button when matching
:defaultto avoid quadratic time on forms with
many non-default submit candidates. - FIX: Fix
:in-rangeand:out-of-rangematching elements whose value,min, ormaxhas a trailing newline;
per HTML, such values are not valid, so they are treated like a missing value and cannot be out of range. - FIX: Fix
:in-rangeand:out-of-rangeraisingValueErrorwhen a date, month, week, or local date and
timeinputhas a year with more digits than Python will convert; such a year is now treated as invalid. - FIX: Fix
:in-rangeand:out-of-rangenot recognizing adatetime-localvalue,min, ormaxthat uses a
single space instead ofTto separate the date and time. - FIX: Search a form only once for checked radio buttons when matching
:indeterminateto avoid quadratic time
on forms with many radio button groups. - FIX:
:lang()now uses thelangattribute of SVG elements, as the HTML specification does (withxml:lang
taking precedence). Previously onlyxml:langwas considered for elements outside the HTML namespace. - FIX:
:definedno longer matches HTML elements with anisattribute (customized built-in elements), which,
like custom elements, are undefined until they are registered. - FIX: Cache the index of each child when matching the general sibling combinator (
a ~ band:has(~ b)) to
avoid quadratic time when the first matching sibling is far into a long list of siblings. - FIX: Match attribute values with the
imodifier using ASCII case insensitivity. - FIX: Treat an
inputwith an unknowntype, such astype="foo", as a text input in:placeholder-shown,
:read-write,:read-onlyand:dir(), as an invalidtypeis in the Text state in the HTML specification. - FIX: Fix
:enabledand:disablednever matchinginputelements withtype="hidden". - FIX:
:requiredno longer matchesinputelements of types therequiredattribute does not apply to
(hidden,range,color,submit,image,resetandbutton). Like in browsers, they match:optional. - FIX: Cache whether an element is or has a matching ancestor when matching the descendant combinator (
a b) to
avoid time that grows with the depth of the document to the power of the number of combinators.