File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -643,6 +643,25 @@ describe("createNdjsonParserStream", () => {
643643 expect ( results ) . toEqual ( [ { id : 1 } , { id : 2 } ] ) ;
644644 } ) ;
645645
646+ it ( "should handle escaped newlines in JSON string values" , async ( ) => {
647+ // JSON.stringify escapes newlines as \n (two chars: backslash + n),
648+ // so they don't break NDJSON line boundaries. This is the normal case
649+ // when the SDK serializes payloads containing newlines.
650+ const item1 = JSON . stringify ( { payload : "line1\nline2\nline3" } ) ;
651+ const item2 = JSON . stringify ( { payload : "no newlines" } ) ;
652+ const ndjson = item1 + "\n" + item2 + "\n" ;
653+ const encoder = new TextEncoder ( ) ;
654+ const stream = chunksToStream ( [ encoder . encode ( ndjson ) ] ) ;
655+
656+ const parser = createNdjsonParserStream ( 1024 ) ;
657+ const results = await collectStream ( stream . pipeThrough ( parser ) ) ;
658+
659+ expect ( results ) . toEqual ( [
660+ { payload : "line1\nline2\nline3" } ,
661+ { payload : "no newlines" } ,
662+ ] ) ;
663+ } ) ;
664+
646665 it ( "should skip empty lines" , async ( ) => {
647666 const ndjson = '{"a":1}\n\n{"b":2}\n \n{"c":3}\n' ;
648667 const encoder = new TextEncoder ( ) ;
You can’t perform that action at this time.
0 commit comments