diff options
author | Mark Nauwelaerts <mark.nauwelaerts@gmail.com> | 2023-01-26 11:23:32 +0100 |
---|---|---|
committer | Mark Nauwelaerts <mark.nauwelaerts@gmail.com> | 2023-01-26 12:11:09 +0100 |
commit | ff112e924cf648f9147c674360c9993dec53136e (patch) | |
tree | 5f6ceb7e1d44bfc2f5120bf0d0ae1d6cf13dba22 /json-glib/json-generator.c | |
parent | d7fb79cfd0a78478206f4bd6ae7dfc543184ed41 (diff) | |
download | json-glib-ff112e924cf648f9147c674360c9993dec53136e.tar.gz |
generator: ensure valid output double exponential notation
Fixes #67
Diffstat (limited to 'json-glib/json-generator.c')
-rw-r--r-- | json-glib/json-generator.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c index 40e9b02..eef41a7 100644 --- a/json-glib/json-generator.c +++ b/json-glib/json-generator.c @@ -360,7 +360,12 @@ dump_value (GString *buffer, g_ascii_dtostr (buf, sizeof (buf), json_value_get_double (value))); /* ensure doubles don't become ints */ - if (g_strstr_len (buf, G_ASCII_DTOSTR_BUF_SIZE, ".") == NULL) + /* also make sure not to append .0 that results in invalid exponential notation + * since the numbers should be decimal, a hex 'e' or "E" can not be mistaken + */ + if (g_strstr_len (buf, G_ASCII_DTOSTR_BUF_SIZE, ".") == NULL && + g_strstr_len (buf, G_ASCII_DTOSTR_BUF_SIZE, "e") == NULL && + g_strstr_len (buf, G_ASCII_DTOSTR_BUF_SIZE, "E") == NULL) { g_string_append (buffer, ".0"); } |