summaryrefslogtreecommitdiff
path: root/ext/json/generator/generator.c
diff options
context:
space:
mode:
authoreno <[email protected]>2025-03-19 22:48:08 +0100
committerHiroshi SHIBATA <[email protected]>2025-03-24 14:35:04 +0900
commit528c08cc5fe8f8c990442885c0a30c95d8798e55 (patch)
tree18cd9ec53e3e7384e78644cb0cca334326b28bc1 /ext/json/generator/generator.c
parenta59333c58bbe0df0baaada6d3cc4a64b0aaf911e (diff)
[ruby/json] Adjust fpconv to add ".0" to integers
Adds a test case fix https://github.com/ruby/json/commit/fa5bdf87cb
Diffstat (limited to 'ext/json/generator/generator.c')
-rw-r--r--ext/json/generator/generator.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 0f028fe072..6ef16ced8f 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -1084,18 +1084,9 @@ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data
char* d = buffer->ptr + buffer->len;
int len = fpconv_dtoa(value, d);
- /* fpconv_dtoa converts a float to its shorted string representation. When
- * converting a float that is exactly an integer (e.g. `Float(2)`) this
- * returns in a string that looks like an integer. This is correct, since
- * JSON treats ints and floats the same. However, to not break integrations
- * that expect a string representation looking like a float, we append a
- * "." in that case.
+ /* fpconv_dtoa converts a float to its shortest string representation,
+ * but it adds a ".0" if this is a plain integer.
*/
- if(!memchr(d, '.', len) && !memchr(d, 'e', len)) {
- d[len] = '.';
- d[len+1] = '0';
- len += 2;
- }
buffer->len += len;
}