Skip to content

fix(parser): forToken cache leak - #22

Open
peaklabs-dev wants to merge 3 commits into
tempestphp:mainfrom
peaklabs-dev:fix/parser-cache-leak
Open

fix(parser): forToken cache leak#22
peaklabs-dev wants to merge 3 commits into
tempestphp:mainfrom
peaklabs-dev:fix/parser-cache-leak

Conversation

@peaklabs-dev

@peaklabs-dev peaklabs-dev commented Aug 4, 2026

Copy link
Copy Markdown

Issue

Parser::$cache was static, so sub-parsers created by forToken() were shared across every Parser instance in the process. The first instance to parse a given token type "won" and its configuration was baked into the cached clone and silently reused by all later instances, regardless of how they were configured.

$first = new Parser();
$first->parse('`x`');

$second = new Parser(highlighter: null);
$second->parse('`<b>x</b>`')->html;
// before: rendered by the cached sub-parser from $first, using its highlighter
// after: rendered with $second's own configuration

Once there are more configuration options like security settings new Markdown(allowedUrlPrefixes: []) and so on this becomes a way bigger issue.

Changes

  • Scope forToken cache per instance
  • Add cache leak regression test

@peaklabs-dev
peaklabs-dev marked this pull request as ready for review August 4, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant