@@ -194,15 +194,17 @@ export function captureRevealedSimKeys(
194194
195195function restoreInString (
196196 content : string ,
197- revealedValues : string [ ]
197+ revealedValues : string [ ] ,
198+ startCursor : number
198199) : {
199200 next : string
200201 changed : boolean
202+ cursor : number
201203} {
202204 if ( ! content . includes ( '<credential>' ) || revealedValues . length === 0 ) {
203- return { next : content , changed : false }
205+ return { next : content , changed : false , cursor : startCursor }
204206 }
205- let cursor = 0
207+ let cursor = startCursor
206208 let changed = false
207209 const next = content . replace ( CREDENTIAL_TAG_PATTERN , ( match , body : string ) => {
208210 const parsed = parseCredentialBody ( body )
@@ -216,7 +218,7 @@ function restoreInString(
216218 }
217219 return match
218220 } )
219- return { next, changed }
221+ return { next, changed, cursor }
220222}
221223
222224/**
@@ -239,11 +241,13 @@ export function restoreRevealedSimKeysForMessage(
239241 return message
240242 }
241243
242- const restoredContent = restoreInString ( message . content , revealed )
244+ const restoredContent = restoreInString ( message . content , revealed , 0 )
243245 let blocksChanged = false
246+ let blockCursor = 0
244247 const nextBlocks : ContentBlock [ ] | undefined = message . contentBlocks ?. map ( ( block ) => {
245248 if ( ! hasRedactedSimKeyTag ( block . content ) ) return block
246- const restored = restoreInString ( block . content as string , revealed )
249+ const restored = restoreInString ( block . content as string , revealed , blockCursor )
250+ blockCursor = restored . cursor
247251 if ( ! restored . changed ) return block
248252 blocksChanged = true
249253 return { ...block , content : restored . next }
0 commit comments