mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix(mcp): gate escaped-json unescape fallback
This commit is contained in:
parent
fcdad69228
commit
ae181825d5
1 changed files with 16 additions and 2 deletions
|
|
@ -65,6 +65,20 @@ export const McpExecution = ({
|
|||
return (trimmed.startsWith("{") && trimmed.endsWith("}")) || (trimmed.startsWith("[") && trimmed.endsWith("]"))
|
||||
}, [])
|
||||
|
||||
const looksLikeEscapedJsonBlob = useCallback(
|
||||
(value: string): boolean => {
|
||||
// Gate the "unescape blob" fallback strictly to avoid mutating arbitrary strings
|
||||
// that merely contain backslashes.
|
||||
// Examples we want to handle:
|
||||
// - `{\"id\":1}`
|
||||
// - `[{\"id\":1}]`
|
||||
const trimmed = value.trim()
|
||||
if (!looksLikeJson(trimmed)) return false
|
||||
return /^\{\\"/.test(trimmed) || /^\[\s*\{\\"/.test(trimmed)
|
||||
},
|
||||
[looksLikeJson],
|
||||
)
|
||||
|
||||
const tryParseJsonValue = useCallback((value: string): unknown | undefined => {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
|
|
@ -108,7 +122,7 @@ export const McpExecution = ({
|
|||
let parsed: unknown | undefined = tryParseJsonValue(trimmed)
|
||||
|
||||
// If initial parse fails, try un-escaping common "JSON encoded as a string blob" patterns.
|
||||
if (parsed === undefined && (trimmed.includes('\\"') || trimmed.includes("\\\\"))) {
|
||||
if (parsed === undefined && looksLikeEscapedJsonBlob(trimmed)) {
|
||||
const unescaped = tryUnescapeJsonBlob(trimmed)
|
||||
if (unescaped !== undefined) {
|
||||
parsed = tryParseJsonValue(unescaped)
|
||||
|
|
@ -137,7 +151,7 @@ export const McpExecution = ({
|
|||
formatted: text,
|
||||
}
|
||||
},
|
||||
[looksLikeJson, tryParseJsonValue, tryUnescapeJsonBlob],
|
||||
[looksLikeEscapedJsonBlob, looksLikeJson, tryParseJsonValue, tryUnescapeJsonBlob],
|
||||
)
|
||||
|
||||
// Only parse response data when expanded AND complete to avoid parsing partial JSON
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue