File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed
Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,32 @@ func TestDemoNdjson(t *testing.T) {
260260 verifyDemoNdjson (pj , t , 0 )
261261}
262262
263+ func TestNdjsonEmptyLines (t * testing.T ) {
264+
265+ ndjson_emptylines := []string {`{"zero":"emptylines"}
266+ {"c":"d"}` ,
267+ `{"single":"emptyline"}
268+
269+ {"c":"d"}` ,
270+ `{"dual":"emptylines"}
271+
272+
273+ {"c":"d"}` ,
274+ `{"triple":"emptylines"}
275+
276+
277+
278+ {"c":"d"}` }
279+
280+ pj := internalParsedJson {}
281+
282+ for _ , json := range ndjson_emptylines {
283+ if err := pj .parseMessageNdjson ([]byte (json )); err != nil {
284+ t .Errorf ("TestNdjsonEmptyLine: got: %v want: nil" , err )
285+ }
286+ }
287+ }
288+
263289func TestNdjsonCountWhere (t * testing.T ) {
264290 ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
265291 pj , err := ParseND (ndjson , nil )
Original file line number Diff line number Diff line change @@ -206,14 +206,16 @@ start_continue:
206206 if done , idx = updateChar (pj , idx ); done {
207207 goto succeed
208208 } else {
209- // For an ndjson object, wrap up current object and start new root
209+ // For an ndjson object, wrap up current object, start new root and check for minimum of 1 newline
210210 if buf [idx ] != '\n' {
211211 goto fail
212212 }
213213
214- // Peek into next character, if we are at the end, exit out
215- if done , idx = updateChar (pj , idx ); done {
216- goto succeed
214+ // Eat any empty lines
215+ for buf [idx ] == '\n' {
216+ if done , idx = updateChar (pj , idx ); done {
217+ goto succeed
218+ }
217219 }
218220
219221 // Otherwise close current root
You can’t perform that action at this time.
0 commit comments