[CDRIVER-291] bson_json_reader_t does not work with trailing \n on files. Created: 01/Mar/14  Updated: 03/May/17  Resolved: 04/Mar/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Christian Hergert Assignee: Christian Hergert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

echo -n '{"hello": "world"}' > test.json
./json-to-bson test.json # works
echo '{"hello": "world"}' > test.json
./json-to-bson test.json # does not work



 Comments   
Comment by Christian Hergert [ 04/Mar/14 ]

Merged, thanks!

Comment by Mira Carey [ 04/Mar/14 ]

https://github.com/mongodb/libbson/pull/28

Comment by Christian Hergert [ 03/Mar/14 ]

I think we want to allow trailing whitespace. So just walk through the trailing utf-8 chars with bson_utf8_get_char()/next_char() and isspace().

The reasoning for allowing it is that anything created in say vim or emacs automatically gets a trailing \n. Same for running a mongo shell command and redirecting into a file. That case should be safe.

Comment by Mira Carey [ 03/Mar/14 ]

This is actually the other way around. -n to echo omits the trailing newline.

I've got the parser complaining about trailing garbage right now, which the trailing newline technically is. I could pretty easily check for that error and ignore trailing whitespace if you think it's worth it, but I think we should choke on trailing characters in general.

Generated at Wed Feb 07 21:09:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.