* Like extractJsonStringField but returns the first `maxLen` characters of the * value even when the closing quote is missing (truncated buffer). Newline * escapes are replaced with spaces and the result is trimmed.
( text: string, key: string, maxLen: number, )
| 4920 | * escapes are replaced with spaces and the result is trimmed. |
| 4921 | */ |
| 4922 | function extractJsonStringFieldPrefix( |
| 4923 | text: string, |
| 4924 | key: string, |
| 4925 | maxLen: number, |
| 4926 | ): string { |
| 4927 | const patterns = [`"${key}":"`, `"${key}": "`] |
| 4928 | for (const pattern of patterns) { |
| 4929 | const idx = text.indexOf(pattern) |
| 4930 | if (idx < 0) continue |
| 4931 | |
| 4932 | const valueStart = idx + pattern.length |
| 4933 | // Grab up to maxLen characters from the value, stopping at closing quote |
| 4934 | let i = valueStart |
| 4935 | let collected = 0 |
| 4936 | while (i < text.length && collected < maxLen) { |
| 4937 | if (text[i] === '\\') { |
| 4938 | i += 2 // skip escaped char |
| 4939 | collected++ |
| 4940 | continue |
| 4941 | } |
| 4942 | if (text[i] === '"') break |
| 4943 | i++ |
| 4944 | collected++ |
| 4945 | } |
| 4946 | const raw = text.slice(valueStart, i) |
| 4947 | return raw.replace(/\\n/g, ' ').replace(/\\t/g, ' ').trim() |
| 4948 | } |
| 4949 | return '' |
| 4950 | } |
| 4951 | |
| 4952 | /** |
| 4953 | * Deduplicates logs by sessionId, keeping the entry with the newest |