diff options
author | drh <> | 2023-12-18 18:31:27 +0000 |
---|---|---|
committer | drh <> | 2023-12-18 18:31:27 +0000 |
commit | fc76750f616a8ceadc9988de67e065b6e274547a (patch) | |
tree | 0ab5efdc559714d88fa28480b6d246a2db0da927 /src | |
parent | 095f2c5082e85d8122225227d3c8923880ef348d (diff) | |
download | sqlite-fc76750f616a8ceadc9988de67e065b6e274547a.tar.gz sqlite-fc76750f616a8ceadc9988de67e065b6e274547a.zip |
Fix JSON to JSONB translation so that it deals correctly with Infinity
and NaN.
FossilOrigin-Name: 178cb84f36bdb45ba17511900d6d8ea8dfa14912fc5bf7094a20348174a36c95
Diffstat (limited to 'src')
-rw-r--r-- | src/json.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/json.c b/src/json.c index 2756590eb..b4b9d8f81 100644 --- a/src/json.c +++ b/src/json.c @@ -3041,13 +3041,29 @@ static int jsonFunctionArgToBlob( } break; } - case SQLITE_FLOAT: + case SQLITE_FLOAT: { + double r = sqlite3_value_double(pArg); + if( sqlite3IsNaN(r) ){ + jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0); + }else{ + int n = sqlite3_value_bytes(pArg); + const char *z = (const char*)sqlite3_value_text(pArg); + if( z==0 ) return 1; + if( z[0]=='I' ){ + jsonBlobAppendNode(pParse, JSONB_FLOAT, 5, "9e999"); + }else if( z[0]=='-' && z[1]=='I' ){ + jsonBlobAppendNode(pParse, JSONB_FLOAT, 6, "-9e999"); + }else{ + jsonBlobAppendNode(pParse, JSONB_FLOAT, n, z); + } + } + break; + } case SQLITE_INTEGER: { int n = sqlite3_value_bytes(pArg); const char *z = (const char*)sqlite3_value_text(pArg); - int e = eType==SQLITE_INTEGER ? JSONB_INT : JSONB_FLOAT; if( z==0 ) return 1; - jsonBlobAppendNode(pParse, e, n, z); + jsonBlobAppendNode(pParse, JSONB_INT, n, z); break; } } |