Skip to content

Commit f9218ec

Browse files
committed
Fix trailing leak
1 parent 6fedb0b commit f9218ec

File tree

1 file changed

+20
-2
lines changed
  • apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content

1 file changed

+20
-2
lines changed

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,28 @@ function extractFileContent(raw: string): string {
460460
const idx = raw.indexOf(marker)
461461
if (idx === -1) return ''
462462
let rest = raw.slice(idx + marker.length).trimStart()
463-
if (rest.startsWith('"')) rest = rest.slice(1)
464-
return rest
463+
if (!rest.startsWith('"')) return rest
464+
465+
// Walk the JSON string value to find the unescaped closing quote.
466+
// While streaming, the closing quote may not have arrived yet — in that
467+
// case we treat everything received so far as the content (no trim).
468+
let end = -1
469+
for (let i = 1; i < rest.length; i++) {
470+
if (rest[i] === '\\') {
471+
i++ // skip escaped character
472+
continue
473+
}
474+
if (rest[i] === '"') {
475+
end = i
476+
break
477+
}
478+
}
479+
480+
const inner = end === -1 ? rest.slice(1) : rest.slice(1, end)
481+
return inner
465482
.replace(/\\n/g, '\n')
466483
.replace(/\\t/g, '\t')
484+
.replace(/\\r/g, '\r')
467485
.replace(/\\"/g, '"')
468486
.replace(/\\\\/g, '\\')
469487
}

0 commit comments

Comments
 (0)