Skip to content

Better parsing of <style>, enhanced support of @supports, SVG embedded images fix #641

Merged
poire-z merged 4 commits intokoreader:masterfrom
poire-z:misc_202512
Dec 8, 2025
Merged

Better parsing of <style>, enhanced support of @supports, SVG embedded images fix #641
poire-z merged 4 commits intokoreader:masterfrom
poire-z:misc_202512

Conversation

@poire-z
Copy link
Copy Markdown
Contributor

@poire-z poire-z commented Dec 7, 2025

text: simplify measureText()'s harfbuzz check

It doesn't seem to be necessary to set usingHarfbuzz on the first font met: the variable doesn't change, and when it's checked, there is always a valid font.
Cherry-picked 3rd commit from unmerged #574 (this one just because it's some forgotten cleanup of my code).

SVG embedded images: handle %-encoded urls

Should allow closing koreader/koreader#13209.

XML parsing: slightly better parsing of <style>

Handle content as text, but don't stop just at any <, only at </style>, as <style> may contain tags.
Not doing that might stop embedded styles parsing prematurously, and put some of it as content text.
Similarly to how we did it for <script> in 997a9a8.
Should allow closing koreader/koreader#12931.
Noticed also at koreader/koreader#14686 (comment) - explained at the bottom of koreader/koreader#14686 (comment).

CSS: improve support of @supports

We failed parsing @supports selector(a > b), moreover ignoring a bunch of valid CSS that follows (until we meet any ))).
Handle better the few specified functionnal syntax elements:

  • @supports selector(a > b): actually checking the selector
  • @supports font-tech(...): we don't support any
  • @supports font-format(...): what we support
  • @supports at-rule(...): what we support (not much)

Also avoid crash if we end up with unbalanced closing parens.
See about this crash at koreader/koreader#14686 (comment) and followups.


This change is Reviewable

bbshelper and others added 4 commits December 7, 2025 17:04
It doesn't seem to be necessary to set usingHarfbuzz on the first font
met: the variable doesn't change, and when it's checked, there is always
a valid font.
Handle content as text, but don't stop just at any '<',
only at '</style>', as <style> may contain tags.
Not doing that might stop embedded styles parsing
prematurously, and put some of it as content text.

Similarly to how we did it for <script> in 997a9a8.
We failed parsing "@supports selector(a > b)", moreover ignoring
a bunch of valid CSS that follows (until we meet any '))').
Handle better the few specified functionnal syntax elements:
- @supports selector(a > b): actually checking the selector
- @supports font-tech(...): we don't support any
- @supports font-format(...): what we support
- @supports at-rule(...): what we support (not much)

Also avoid crash if we end up with unbalanced closing parens.
@poire-z poire-z merged commit c5d9097 into koreader:master Dec 8, 2025
1 check passed
@poire-z poire-z deleted the misc_202512 branch December 8, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants