mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-01 21:20:44 +00:00
fix(core): avoid corrupting JSON strings in SSE whitespace normalization
Replace broad \s+} and \s+] regexes with a narrower pattern that only
strips whitespace before closing braces/brackets when preceded by a
JSON value terminator (", digit, ] or }). Prevents mangling string
values like "hello }" which contain whitespace before braces.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1b651d5c4f
commit
cf7204118f
1 changed files with 4 additions and 4 deletions
|
|
@ -111,10 +111,10 @@ export function parseAnthropicSseData(
|
|||
//
|
||||
// Try to fix by removing whitespace before } and ]
|
||||
|
||||
// Remove trailing whitespace before closing braces
|
||||
normalizedData = normalizedData.replace(/\s+}/g, '}');
|
||||
// Remove trailing whitespace before closing brackets
|
||||
normalizedData = normalizedData.replace(/\s+]/g, ']');
|
||||
// Remove trailing whitespace before closing braces/brackets, but only
|
||||
// when preceded by a JSON value terminator (" or digit or ] or })
|
||||
// to avoid corrupting whitespace inside string values like "hello }".
|
||||
normalizedData = normalizedData.replace(/(["\d\]}])\s+([\]}])/g, '$1$2');
|
||||
|
||||
try {
|
||||
return JSON.parse(normalizedData) as AnthropicStreamEvent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue