mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-03 11:00:58 +08:00
## Problem
Commit 63e31ae introduced a regex pattern that was too permissive:
```go
reJSONFence = regexp.MustCompile("(?is)```(?:json[a-z0-9_-]*)?\...")
```
This could match ANY code block (```text, ```js, etc.), not just JSON.
## Issues
1. **Wrong Match**: Could extract from non-JSON code blocks
2. **Escaping**: Triple backticks in double quotes may cause issues
3. **Too Loose**: Regex accepts ```, ```json, ```json5, etc.
## Fix
Revert to safe, precise regex:
```go
reJSONFence = regexp.MustCompile(`(?is)` + "```json\s*...")
```
- ✅ Only matches ```json code blocks
- ✅ Uses backticks + string concat to avoid escaping
- ✅ Keeps performance optimization (precompiled)
## Testing
- ✅ Compiles successfully
- ✅ Regex patterns verified
- ✅ No syntax errors
Related: #regex #json-extraction #bug-fix
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>