-
-
Notifications
You must be signed in to change notification settings - Fork 474
Ignore NaN and infinite values in json::wvalue #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
--- include/crow/json.h (before formatting)
+++ include/crow/json.h (after formatting)
@@ -1774,8 +1774,9 @@
{
if (v.nt == num_type::Floating_point)
{
- if(isnan(v.num.d) || isinf(v.num.d)){
- CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), ignoring" ;
+ if (isnan(v.num.d) || isinf(v.num.d))
+ {
+ CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), ignoring";
break;
}
#ifdef _MSC_VER |
Sorry to jump into the middle, but does the change cause broken json to be
generated?
The number is completely missing from the output. (My apologies, if not, I
have not actually tested this). Causing adjacent commas in arrays and
broken json objects.
I do not have a good solution to this, maybe output 0 or a "very large
number", although I might actually prefer null so that it would not be
"syntax broken", but "value broken".
I guess correctly removing the value from an object, by also removing the
name of the value would be OK, but I don't see any nice way for handling
arrays, because the meaning of a missing value depends on the application,
it might be insignificant or it may change the remaining data completely.
Eero
…On Tue, Feb 1, 2022 at 11:53 PM Vhuynh25 ***@***.***> wrote:
------------------------------
You can view, comment on, or merge this pull request online at:
#328
Commit Summary
- 9af906d
<9af906d>
fixed JSON outputting NaN and infinite values
- a134e2b
<a134e2b>
fixed NaN handling errors
- c21ae7e
<c21ae7e>
change NaN output warning message
File Changes
(1 file <https://github.com/CrowCpp/Crow/pull/328/files>)
- *M* include/crow/json.h
<https://github.com/CrowCpp/Crow/pull/328/files#diff-db109b2ea21b65a24a13f75598bfaf13f87d66cb08f042eb170c6b708c46caac>
(6)
Patch Links:
- https://github.com/CrowCpp/Crow/pull/328.patch
- https://github.com/CrowCpp/Crow/pull/328.diff
—
Reply to this email directly, view it on GitHub
<#328>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG5D7LMVJYII3UKUF325VLUZBI6TANCNFSM5NKLTCJA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
--- include/crow/json.h (before formatting)
+++ include/crow/json.h (after formatting)
@@ -1774,7 +1774,7 @@
{
if (v.nt == num_type::Floating_point)
{
- if(isnan(v.num.d) || isinf(v.num.d))
+ if (isnan(v.num.d) || isinf(v.num.d))
{
CROW_LOG_WARNING << "Invalid JSON value detected (" << v.num.d << "), ignoring";
break; |
@epajarre I've recently had time to test the PR and you were right, it does seem to produce incorrect JSON whether the invalid value is in an object or an array. It seems that omitting the value (and key) properly will take more work than just outputting @Vhuynh25 I am very sorry for this change in scope and taking your time, Would you be interested in changing your code to output Additionally for some reason I couldn't compile Crow locally until I changed |
also changed from <cmath> to <math.h>
Thank you for your help @Vhuynh25, and for adapting your code to the change in scope. I'll run my local tests to check that everything is in order (and possibly push those tests as unit tests) and merge the PR. |
No description provided.