slides: a web link whose address contains a dollar sign works again - #489
Merged
Merged
Conversation
… formulas are matched in text runs only resolveMath ran its $…$ rule over the whole sanitized HTML, so an href carrying $a$b (#465) had a <math> written into the attribute: a dead link and stray markup. Nothing an author chose became an attribute — the sanitizer had already run — but the link was gone. The string is now split on tags and only the text runs are transformed, so a dollar in a tag never pairs, and a pair split across a tag boundary does not pair either. Rig: scripts/test-slides-math-href.ts (12 checks), in CI.
Build size
Updated: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A web link whose address contains a dollar sign works again.
The bug (on main since web links arrived in #465, independent of the maths engine):
resolveMathran its$…$rule over the whole sanitized HTML, so<a href="https://x.example/$a$b">had its two dollars paired as an inline formula and a<math>written into the attribute — the xmlns quote ended the href and the>closed the tag: a dead link plus stray markup. Not exploitable: the sanitizer had already run, so nothing an author chose became an attribute. An integrity bug.The fix, minimal, on the existing Temml-based
resolveMath: split the string on tags (/(<[^>]*>)/), transform only the text runs, rejoin. A$inside any tag never pairs with anything; a pair split across a tag boundary does not pair either; a formula wholly inside<b>…</b>still renders; the fussy inline rule (no whitespace inside, no digit after) is unchanged.Measured in Chrome on the built shell:
see <a href="https://x.example/$a$b">the link</a> and $x^2$ after→ the link keepshref="https://x.example/$a$b", is clickable (pointer-events on, 103 px wide), no stray markup in the text, and$x^2$beside it renders as one<math>; on the sidebar thumbnail the href is intact too;a $b <b>c$ d</b>renders no<math>. Zero console errors.Rig
scripts/test-slides-math-href.ts— 12 checks: the source holds the split and the text-run function (a mutant that calls the rule on the whole HTML goes red), and the behaviour with the same split and regexes:$inside href untouched and the link intact; a formula in text beside a link renders with the href whole; a pair across a tag boundary does not pair; a formula inside a tag renders; a$in the href with a price in the link text; display maths before a tag; prose with prices; any attribute, not just href. Registered in CI after the fields rig; ci-registered 338/338; typecheck OK. CHANGELOG line under [Unreleased].