Repository navigation
fix(images): embed image paths with parentheses - #4
Merged
lecstor merged 2 commits intoNov 6, 2026
Merged
Conversation
`.png)` and `.png)` were cut at the first `)`, so the export read the wrong file and either stopped with a truncated name or, for a reference that still closed, sent the path unembedded. A bare destination now ends at the `)` that balances the one in `](`, as CommonMark and the service's parser read it, with backslash-escaped parentheses skipped. When that does not close the reference, the scan falls back to the run up to the first `)`, so `` still reads `u(v.png`. The backslash in `\(`, `\)`, `\<` and `\>` is removed from a bare path before it is read from disk; other backslashes and paths inside `<...>` are left as written. The parentheses are matched once per whitespace-free run and reused by every attempt starting inside it, so the scan stays linear on runs of unterminated or unbalanced references.
Review of 4198257 found: - A pre-existing quadratic: every failed attempt whose src ends at the same whitespace block skipped the whole block again, so 20,000 `. - ParenMemo recorded every `(` in a run, about 55 bytes a character: `. - The docstring now says a Windows separator directly before `(`, `)`, `<` or `>` reads as an escape, and that `<...>` keeps it. Tests pin the whitespace shapes and reuse of a match within one run.
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.
MAK-356. A markdown image whose path contains parentheses, such as
.png), was cut at the first). The export then read the wrong file. When that file was missing, it stopped with a truncated name likea(b. When the cut still closed the reference, the remainder of the path was left in the text.What changes
In
server/src/images.ts, a bare destination now ends at the)that balances the(in](, as CommonMark and the service's parser (marked) read it. Backslash-escaped parentheses are skipped..png)a(b).png).png)a((b)).png(any depth).png)a(b).png.png)c (d).png.png>)c (d).png(already worked)u(v.png(fallback, as before).png)missing(1).png).\(,\),\<and\>is removed from a bare path before reading. This matches the VS Code and browser fixes. Other backslashes, including Windows separators, and paths inside<...>are left as written. "t")now readsu(v.png)(extension.png), so it is left alone), as the server reads it. Before, it embeddedu(v.pngand left"t")in the text.ImageFailure.srcis now the path as read, so an escaped name is reported without its backslashes.Linearity
The parentheses of each whitespace-free run are matched once, the first time an attempt starts inside it. Every later attempt in that run reuses the result, and attempts move forward only, so total work is linear. Only a
(that follows a]is recorded; other parentheses are counted, so memory does not grow with them.The second commit fixes a quadratic case that predates this branch. Every failed attempt whose src ended at the same whitespace block skipped the whole block again: 20,000
repeatedrunsEach roughly doubles per doubling of size.
, compared old and new on 300k inputs, and checked hrefs against marked 15. Fixed in the second commit:
The fuzz re-run on the second commit also shows no differences. That commit has not had a separate review.
Known limits
(,),<or>reads as an escape..png)readsC:\pics(1).png; write<C:\pics\(1).png>instead. marked reads it the same way..png), the innerc(d).pngis neither embedded nor reported. The first-)fallback swallows it, while marked rejects the outer reference and renders the inner one, which the service cannot fetch.mainbehaves the same.<...>is read as written, backslashes included. marked unescapes\(there, so<pics\(1).png>readspics\(1).pnghere andpics(1).pngon the server.Checks
npm testinserver/: typecheck, 54 unit tests (7 new), 6 integration testsnpm run buildNot run inside Zed.