Skip to content

Commit c29941e

Browse files
committed
Fix trailing leak
1 parent 8dfbe8a commit c29941e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

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

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
@@ -538,10 +538,28 @@ function extractFileContent(raw: string): string {
538538
const idx = raw.indexOf(marker)
539539
if (idx === -1) return ''
540540
let rest = raw.slice(idx + marker.length).trimStart()
541-
if (rest.startsWith('"')) rest = rest.slice(1)
542-
return rest
541+
if (!rest.startsWith('"')) return rest
542+
543+
// Walk the JSON string value to find the unescaped closing quote.
544+
// While streaming, the closing quote may not have arrived yet — in that
545+
// case we treat everything received so far as the content (no trim).
546+
let end = -1
547+
for (let i = 1; i < rest.length; i++) {
548+
if (rest[i] === '\\') {
549+
i++ // skip escaped character
550+
continue
551+
}
552+
if (rest[i] === '"') {
553+
end = i
554+
break
555+
}
556+
}
557+
558+
const inner = end === -1 ? rest.slice(1) : rest.slice(1, end)
559+
return inner
543560
.replace(/\\n/g, '\n')
544561
.replace(/\\t/g, '\t')
562+
.replace(/\\r/g, '\r')
545563
.replace(/\\"/g, '"')
546564
.replace(/\\\\/g, '\\')
547565
}

0 commit comments

Comments
 (0)