← Back to PRs

#19868: fix: prevent media token regex from matching markdown bold text

by sanketgautam open 2026-02-18 07:57 View on GitHub →
agents size: XS
Fixes #19847 ## Problem `extractToolResultMediaPaths` matched markdown bold markers (`**text**`) as media tokens, causing false positives like `**I` being treated as a file path. ## Changes - **src/media/parse.ts**: Export `isValidMedia()` function that validates extracted paths against known media extensions and patterns - **src/agents/pi-embedded-subscribe.tools.ts**: Add `isValidMedia()` validation before accepting extracted paths - **src/media/parse.test.ts**: Add regression tests for bold text false positives ## Testing - 2 regression tests added verifying `**text**` patterns are rejected - Existing tests pass --- *Replaces #19855 which was closed due to an accidentally committed log file. This PR has clean history — no PII.* <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes false positives in `extractToolResultMediaPaths` where any non-empty string under 4096 characters after a `MEDIA:` token was accepted as a valid media path. The fix reuses the existing `isValidMedia()` validator from `src/media/parse.ts` (previously module-private, now exported) to ensure extracted strings are structurally valid media references (URLs, local file paths, or bare filenames with extensions). This aligns `extractToolResultMediaPaths` with the same validation already used in `splitMediaFromOutput`. - Replaced weak `p.length <= 4096` guard with `isValidMedia(p, { allowSpaces: true })` in `extractToolResultMediaPaths` - Exported `isValidMedia` from `src/media/parse.ts` (no logic changes to the function itself) - Added 2 regression tests covering markdown bold patterns and non-path strings <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — it tightens validation using an existing, well-tested function with no behavioral regressions. - The change is minimal and well-scoped: it replaces a weak length-only guard with an existing structural validator (`isValidMedia`) that was already battle-tested in `splitMediaFromOutput`. The function's logic is unchanged — only its visibility is widened via `export`. The new validation is strictly more restrictive than the old check (anything passing `isValidMedia` also passes `length <= 4096`), so no existing valid media paths are rejected. Regression tests are included. - No files require special attention <sub>Last reviewed commit: 6557c99</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs