diff --git a/c/input/lrec_reader_stdio_json.c b/c/input/lrec_reader_stdio_json.c index 592f90717..427cd54e6 100644 --- a/c/input/lrec_reader_stdio_json.c +++ b/c/input/lrec_reader_stdio_json.c @@ -160,8 +160,9 @@ static void lrec_reader_stdio_json_sof(void* pvstate, void* pvhandle) { pstate->comment_handling, pstate->comment_string, line_term); } mlr_json_end_strip(phandle->sof, &phandle->eof); + length = phandle->eof - phandle->sof; - if (phandle->sof >= phandle->eof) { + if (length > 0) { while (TRUE) { parsed_top_level_json = json_parse(item_start, length, error_buf, &item_start); diff --git a/c/reg_test/expected/out b/c/reg_test/expected/out index dafeac6de..6fe0777fc 100644 --- a/c/reg_test/expected/out +++ b/c/reg_test/expected/out @@ -45267,6 +45267,97 @@ mlr --pass-comments --inidx --oxtab cat ./reg_test/input/comments/comments3.nidx # hello world 3 +================================================================ +SKIP/PASS COMMENTS JSON + + +---------------------------------------------------------------- input comments1.json +cat ./reg_test/input/comments/comments1.json +# hello world 1 +{ "a":1, "b":2, "c":3 } +{ "a":4, "b":5, "c":6 } + + +---------------------------------------------------------------- skip comments1.json +mlr --skip-comments --ijson --odkvp cat +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --skip-comments --ijson --odkvp cat ./reg_test/input/comments/comments1.json +a=1,b=2,c=3 +a=4,b=5,c=6 + + +---------------------------------------------------------------- pass comments1.json +mlr --pass-comments --ijson --odkvp cat +# hello world 1 +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --pass-comments --ijson --odkvp cat ./reg_test/input/comments/comments1.json +# hello world 1 +a=1,b=2,c=3 +a=4,b=5,c=6 + + +---------------------------------------------------------------- input comments2.json +cat ./reg_test/input/comments/comments2.json +{ "a":1, "b":2, "c":3 } +# hello world 2 +{ "a":4, "b":5, "c":6 } + + +---------------------------------------------------------------- skip comments2.json +mlr --skip-comments --ijson --odkvp cat +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --skip-comments --ijson --odkvp cat ./reg_test/input/comments/comments2.json +a=1,b=2,c=3 +a=4,b=5,c=6 + + +---------------------------------------------------------------- pass comments2.json +mlr --pass-comments --ijson --odkvp cat +# hello world 2 +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --pass-comments --ijson --odkvp cat ./reg_test/input/comments/comments2.json +# hello world 2 +a=1,b=2,c=3 +a=4,b=5,c=6 + + +---------------------------------------------------------------- input comments3.json +cat ./reg_test/input/comments/comments3.json +{ "a":1, "b":2, "c":3 } +{ "a":4, "b":5, "c":6 } +# hello world 3 + + +---------------------------------------------------------------- skip comments3.json +mlr --skip-comments --ijson --odkvp cat +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --skip-comments --ijson --odkvp cat ./reg_test/input/comments/comments3.json +a=1,b=2,c=3 +a=4,b=5,c=6 + + +---------------------------------------------------------------- pass comments3.json +mlr --pass-comments --ijson --odkvp cat +# hello world 3 +a=1,b=2,c=3 +a=4,b=5,c=6 + +mlr --pass-comments --ijson --odkvp cat ./reg_test/input/comments/comments3.json +# hello world 3 +a=1,b=2,c=3 +a=4,b=5,c=6 + + ================================================================ MMAP AT PAGE BOUNDARIES diff --git a/c/reg_test/run b/c/reg_test/run index 8e3bcc8bb..a62350102 100755 --- a/c/reg_test/run +++ b/c/reg_test/run @@ -5241,6 +5241,44 @@ mention pass comments3.nidx run_mlr --pass-comments --inidx --oxtab cat < $indir/comments/comments3.nidx run_mlr --pass-comments --inidx --oxtab cat $indir/comments/comments3.nidx +# ---------------------------------------------------------------- +announce SKIP/PASS COMMENTS JSON + +mention input comments1.json +run_cat $indir/comments/comments1.json + +mention skip comments1.json +run_mlr --skip-comments --ijson --odkvp cat < $indir/comments/comments1.json +run_mlr --skip-comments --ijson --odkvp cat $indir/comments/comments1.json + +mention pass comments1.json +run_mlr --pass-comments --ijson --odkvp cat < $indir/comments/comments1.json +run_mlr --pass-comments --ijson --odkvp cat $indir/comments/comments1.json + + +mention input comments2.json +run_cat $indir/comments/comments2.json + +mention skip comments2.json +run_mlr --skip-comments --ijson --odkvp cat < $indir/comments/comments2.json +run_mlr --skip-comments --ijson --odkvp cat $indir/comments/comments2.json + +mention pass comments2.json +run_mlr --pass-comments --ijson --odkvp cat < $indir/comments/comments2.json +run_mlr --pass-comments --ijson --odkvp cat $indir/comments/comments2.json + + +mention input comments3.json +run_cat $indir/comments/comments3.json + +mention skip comments3.json +run_mlr --skip-comments --ijson --odkvp cat < $indir/comments/comments3.json +run_mlr --skip-comments --ijson --odkvp cat $indir/comments/comments3.json + +mention pass comments3.json +run_mlr --pass-comments --ijson --odkvp cat < $indir/comments/comments3.json +run_mlr --pass-comments --ijson --odkvp cat $indir/comments/comments3.json + # ---------------------------------------------------------------- announce MMAP AT PAGE BOUNDARIES