You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When writing a json file using yyjson_mut_write_fp (and probably others but I haven't tested them), even when using YYJSON_WRITE_PRETTY or YYJSON_WRITE_PRETTY_TWO_SPACES, the resulting file will have no newline at the end. While it might be justifiable with minimized output, according to POSIX, these are not text files (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403 and https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206) which produce various problems when trying to use these files. E.g. if you cat one of these files, the closing } will end up before your shell prompt but the shell will think it's not there and mess up cursor movement commands, diff files will have an ugly \ No newline at end of file at the end, busybox based utilities sometimes ignore the last line in these files (which is technically correct, since you're feeding binary garbage into an utility that expects a text file), etc.
Your environment
OS: Gentoo Linux amd64
Compiler: gcc 13.2.1
The text was updated successfully, but these errors were encountered:
I see. jq on the other hand adds the trailing \n. I'm also fine with an option.
(Right now I'm only using the fp version because I'm writing to stdout in my toy example now, but later I want to move to files where I can't just putchar('\n') after yyjson_mut_write_file.)
Describe the bug
When writing a json file using
yyjson_mut_write_fp
(and probably others but I haven't tested them), even when usingYYJSON_WRITE_PRETTY
orYYJSON_WRITE_PRETTY_TWO_SPACES
, the resulting file will have no newline at the end. While it might be justifiable with minimized output, according to POSIX, these are not text files (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403 and https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206) which produce various problems when trying to use these files. E.g. if youcat
one of these files, the closing}
will end up before your shell prompt but the shell will think it's not there and mess up cursor movement commands, diff files will have an ugly\ No newline at end of file
at the end, busybox based utilities sometimes ignore the last line in these files (which is technically correct, since you're feeding binary garbage into an utility that expects a text file), etc.Your environment
The text was updated successfully, but these errors were encountered: