v1.59.2.0 fix(make-pdf): stop smartypants URL carve from swallowing the next placeholder (#2084)#2108
Open
genisis0x wants to merge 2 commits into
Open
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
…aceholder (garrytan#2084) The URL carve used \S+, which matches non-whitespace and so eats the U+0000 sentinel of a following placeholder token. For an autolinked URL (<a href=URL>URL</a>), the link-text URL swallowed the </a> placeholder, nesting it so neither restored: a raw SMARTPANTS_PRESERVED_n token leaked into the rendered text and the unclosed <a> bled link styling into every later block. Exclude U+0000 from the URL character class so the match stops at the placeholder boundary. Adds a regression test that fails on the old greedy regex.
973c629 to
28329d0
Compare
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.
Closes #2084.
make-pdf generatemangled any bare/autolinkedhttp(s)://URL into a literalSMARTPANTS_PRESERVED_<n>token and left an unclosed<a>that bled link-blue into every following block to the end of the document.Root cause
make-pdf/src/smartypants.tscarves code/tags/URLs into U+0000-delimited placeholder tokens, transforms the remaining text, then restores the tokens. The URL pattern was/\bhttps?:\/\/\S+/g.\Smatches non-whitespace, and the placeholder delimiter U+0000 is non-whitespace, so for an autolinked URL (<a href="URL">URL</a>) the link-text URL match greedily swallowed the trailing</a>placeholder. The nested placeholder never restored (the restore is a single left-to-right pass), soSMARTPANTS_PRESERVED_<n>leaked into the text and the</a>was dropped.Fix
Exclude U+0000 from the URL character class (
[^\s]+) so the URL match stops at the placeholder boundary. Real URLs never contain U+0000, so the match is identical to\S+except that it no longer crosses a carve boundary.Before / after on the issue's repro (via the real
smartypants()):<a href="https://example.com">https://example.com SMARTPANTS_PRESERVED_2 here.(leak, no</a>)<a href="https://example.com">https://example.com</a> here.Test
Added a regression test in
make-pdf/test/render.test.ts(the existingsmartypantsblock): an autolinked URL keeps its<a>...</a>intact and leaks no placeholder. Verified it fails on the old\S+regex and passes on the fix. Fullrender.test.ts: 67 pass. Quotes, em dashes, ellipses, code/pre zones, and href-only URLs are unaffected.