jsoup Java HTML Parser release 1.16.2
jsoup 1.16.2 is out now with faster CSS selector execution via a cost-based query planner, better support for
svg elements, and a bunch of other improvements and bug fixes.
jsoup is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of HTML5 DOM methods and CSS selectors.
Download jsoup now.
- Optimized the performance of complex CSS selectors, by adding a cost-based query planner. Evaluators are sorted by their relative execution cost, and executed in order of lower to higher cost. This speeds the matching process by ensuring that simpler evaluations (such as a tag name match) are conducted prior to more complex evaluations (such as an attribute regex, or a deep child scan with a :has).
- Added support for
<math>tags (and their children). This includes tag namespaces and case preservation on applicable tags and attributes.
- When converting jsoup Documents to W3C Documents in
W3CDom, HTML documents will be placed in the
http://www.w3.org/1999/xhtmlnamespace by default, per the HTML5 spec. This can be controlled by setting
- Speed optimized the Structural Evaluators by memoizing previous evaluations. Particularly the
~(any preceding sibling) and
:nth-of-typeselectors are improved.
- Tweaked the performance of the
firstElementChild, and `lastElementChild. They now inplace filter/skip in the child-node list, vs having to allocate and scan a complete Element filtered list.
- Optimized internal methods that previously called
Element.children()to use filter/skip child-node list accessors instead, reducing new Element List allocations.
- Tweaked the performance of parsing
- When using the
:emptypseudo-selector, blank textnodes are now considered empty. Previously, an element containing any whitespace was not considered empty.
- In forms,
<input type="image">should be excluded from
Element.formData()(and hence from form submissions).
formelements and empty elements (such as
img) did not have their attributes de-duplicated.
Jsoup.connect(String url), URL paths containing a %2B were incorrectly recoded to a '+', or a '+' was recoded to a ' '. Fixed by reverting to the previous behavior of not encoding supplied paths, other than normalizing to ASCII.
Jsoup.connect(String url), strings containing supplemental characters (e.g. emoji) were not URL escaped correctly.
Jsoup.connect(String url), the ConstrainableInputStream would clear Thread interrupts when reading the body. This precluded callers from spawning a thread, running a number of requests for a length of time, then joining that thread after interrupting it.
- When tracking HTML source positions, the closing tags for
H6elements were not tracked correctly.
- When calling
Element.cssSelector()on an extremely deeply nested element, a
StackOverflowErrorcould occur. Further, a
StackOverflowErrormay occur when running the query.
- Appending a node back to its original
empty()would throw an Index out of bounds exception. Also, now the child nodes that were removed have their parent node cleared, fully detaching them from the original parent.
Connectionwhen adding headers, the value may have been assumed to be an incorrectly decoded
ISO_8859_1string, and re-encoded as
UTF-8. The value is now left as-is.
- Removed previously deprecated methods
Node.forEach(org.jsoup.helper.Consumer<>), and the
org.jsoup.helper.Consumerinterface; the latter being a previously required compatibility shim prior to Android's de-sugaring support.
- The previous compatibility shim
org.jsoup.UncheckedIOExceptionis deprecated in favor of the now supported
java.io.UncheckedIOException. If you are catching the former, modify your code to catch the latter instead.
noscripttags from being added to Safelists, due to incompatibilities between parsers with and without script-mode enabled.
My sincere thanks to everyone who contributed patches, suggestions, and bug reports. If you have any suggestions for the next release, I would love to hear them; please get in touch with me directly.