Skip to content

fix(images): fetch image paths with parentheses - #2

Merged
lecstor merged 2 commits into
mainfrom
fix/image-paths-with-parentheses
Nov 5, 2026
Merged

lecstor merged 2 commits into
mainfrom
fix/image-paths-with-parentheses

Conversation

@lecstor

@lecstor lecstor commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

MAK-355. Same bug as makesPDF/makespdf-obsidian-plugin#17, in a different pattern.

Bug

![x](a(b).png) stopped reading the path at the first ), so the extension tried to fetch a(b, failed, and stopped the export over an image that exists. ![x](a\(b\).png) and ![x](c%20(d).png) failed the same way, reproduced against main.

Change

  • MD_IMAGE accepts parentheses balanced to two levels and backslash-escaped parentheses, and keeps the first-) reading for an unbalanced (, which already worked.
  • cleanMarkdownSrc undoes \(, \), \< and \> in bare destinations, and only \< and \> inside angle brackets, where a backslash before a parenthesis is a Windows path separator (<pics\(1).png>). HTML src values have no such escapes and stay on cleanSrc.

Verification

npm test: 102 passed, 8 of them new, including unterminated destinations and a 16 MB data URI in both bare and angle form. npm run typecheck, npm run build and npm run verify:packages pass. Timings match the old pattern on the repeated and unterminated inputs measured up to 80,000 characters.

An independent review agent ran on the first commit; its findings are fixed in the second, which has not had a separate review. The reviewer ran the URL logic of src/adapters/github.ts under new URL for these paths with correct results, but with no real fetch.

Not checked

A real GitHub fetch of such a path, or a run in a browser.

Known limits

  • Three or more levels of nested parentheses still truncate at the first ). Use angle brackets for those.
  • An ambiguous (see ![a](u(v.png)) or ![a](u(v.png) "t") now reads the path as u(v.png), which matches the server's parser. The old pattern read u(v.png.
  • A bare destination of several million characters of (a) or \( can overflow the regex stack. It is far over the 5 MB image limit and the export reports a misleading fetch error.

`![x](a(b).png)` stopped reading the path at the first `)`, so the extension
tried to fetch `a(b`, failed, and stopped the export over an image that
exists.

The destination now accepts balanced and backslash-escaped parentheses and
escaped angle brackets, and keeps the old first-`)` reading for an unbalanced
`(`. Backslash escapes are undone for markdown images only.
Review found regressions in the new destination pattern:
- `![x](my\ photo.png)` became a path, because `\.` accepted whitespace.
- `![x](<pics\(1).png>)` lost its backslash, a path separator on Windows.
  Inside angle brackets only `\<` and `\>` are escapes now.
- `![x](<a<b c.png>)` stopped matching. Unescaped `<` is allowed again.

Also handles a second level of nested parentheses, and unrolls the angle
branch, which overflowed the stack above about 8 million characters.
@lecstor
lecstor merged commit 4614a27 into main Nov 5, 2026
1 check passed
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.

1 participant