fix(ts): extract content from code blocks instead of deleting it#4317
Merged
whysosaket merged 1 commit intomem0ai:mainfrom Mar 14, 2026
Merged
Conversation
The removeCodeBlocks regex /```[^`]*```/g replaced entire code
blocks (including their content) with an empty string. When Claude or
other LLMs returned JSON wrapped in markdown code fences like:
```json
{"facts": ["saved fact"]}
```
the parser received an empty string and threw SyntaxError.
Fix: use a capturing group to extract the inner content of code fences
while stripping the fence markers themselves.
Fixes mem0ai#4108
|
|
utkarsh240799
approved these changes
Mar 14, 2026
Contributor
|
Thanks for your contribution @voidborne-d . Can you sign the CLA? |
Contributor
Author
|
Thanks @utkarsh240799! Just signed the CLA ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
whysosaket
approved these changes
Mar 14, 2026
This was referenced Mar 16, 2026
This was referenced Mar 16, 2026
Closed
jamebobob
pushed a commit
to jamebobob/mem0-vigil-recall
that referenced
this pull request
Mar 29, 2026
…0ai#4317) Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com>
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.
Problem
Fixes #4108 —
removeCodeBlocksdeletes entire code blocks (including their JSON payload) instead of extracting the content inside them.The regex
/ ```[^]*``` /g` matches everything between the opening and closing fence markers and replaces all of it with an empty string. When Claude returns:Tests
Added
remove-code-blocks.test.tscovering:```jsonfence```fence