diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-26 10:41:37 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-26 10:47:56 +0100 |
commit | 3f6d1998b60e2778730a925d2b761db3b54979fe (patch) | |
tree | 3150ccd20772ee2406d3024a9b930f6051f6c028 | |
parent | aa860a35252b4833a188f8b2f9c6a7d68963767d (diff) |
vallist: uc_number_parse(): parse empty strings as `0`, not `NaN`
Fixes: b605dbf ("treewide: rework numeric value handling")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | tests/custom/04_bugs/29_empty_string_as_number | 17 | ||||
-rw-r--r-- | vallist.c | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/tests/custom/04_bugs/29_empty_string_as_number b/tests/custom/04_bugs/29_empty_string_as_number new file mode 100644 index 0000000..675f8a1 --- /dev/null +++ b/tests/custom/04_bugs/29_empty_string_as_number @@ -0,0 +1,17 @@ +When an empty string was casted to a number, e.g. explicitly through `+` +or `int()` or implicitly through numerical calculations, it was incorrectly +treated as `NaN` and not `0`. + +-- Testcase -- +{{ +"" }} +{{ int("") }} +{{ "" + 0 }} +{{ "" - 0.0 }} +-- End -- + +-- Expect stdout -- +0 +0 +0 +0 +-- End -- @@ -62,7 +62,7 @@ uc_number_parse(const char *buf, char **end) p++; } - if (!isxdigit(*p)) + if (*p != 0 && !isxdigit(*p)) return NULL; if (!end) @@ -73,7 +73,7 @@ uc_number_parse(const char *buf, char **end) if (**end == '.' || **end == 'e' || **end == 'E') { d = strtod(p, end); - if (*end == p || (!isspace(**end) && **end != 0)) + if (!isspace(**end) && **end != 0) return NULL; if (neg) @@ -82,7 +82,7 @@ uc_number_parse(const char *buf, char **end) return ucv_double_new(d); } - if (*end == p || (!isspace(**end) && **end != 0)) + if (!isspace(**end) && **end != 0) return NULL; if (neg) { |