couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Newson (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COUCHDB-1407) JSON encoding of number changes
Date Sat, 11 Feb 2012 18:08:59 GMT

    [ https://issues.apache.org/jira/browse/COUCHDB-1407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206212#comment-13206212
] 

Robert Newson commented on COUCHDB-1407:
----------------------------------------

Parity is restored as easily as;

diff --git a/src/ejson/encode.c b/src/ejson/encode.c
index 916a0b7..134ffca 100644
--- a/src/ejson/encode.c
+++ b/src/ejson/encode.c
@@ -146,7 +146,7 @@ final_encode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
                 }
                 // write the string into the buffer
                 snprintf((char*)ctx.bin.data+ctx.fill_offset, 32,
-                        "%.16g", number);
+                        "%.16f", number);
                 // increment the length
                 ctx.fill_offset += strlen((char*)ctx.bin.data+ctx.fill_offset);
             }

The obvious downside is that, by not taking the shorter of the %e and %f formats, numbers
will be less concisely persisted.
                
> JSON encoding of number changes
> -------------------------------
>
>                 Key: COUCHDB-1407
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1407
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>    Affects Versions: 1.2
>         Environment: Ubuntu 12.04 (alpha)
>            Reporter: Adam Lofts
>
> JSON encoding of Number has changed from 1.0.2 to 1.2. JSON only defines Number but this
change causes issues in my app because python decodes the number as an int in 1.2.
> Test case:
> PORT=5985
> curl -X DELETE http://localhost:$PORT/test-floats/
> curl -X PUT http://localhost:$PORT/test-floats/
> curl -X PUT http://localhost:$PORT/test-floats/doc1 -H "Content-Type: application/json"
-d "{ \"a\": 1.0 }"
> curl http://localhost:$PORT/test-floats/doc1
> Run against 1.0.2:
> {"ok":true}
> {"ok":true}
> {"ok":true,"id":"doc1","rev":"1-78e61304147429d3d500aee7806fd26d"}
> {"_id":"doc1","_rev":"1-78e61304147429d3d500aee7806fd26d","a":1.0}
> Run against 1.2:
> {"ok":true}
> {"ok":true}
> {"ok":true,"id":"doc1","rev":"1-78e61304147429d3d500aee7806fd26d"}
> {"_id":"doc1","_rev":"1-78e61304147429d3d500aee7806fd26d","a":1}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message