diff --git a/source/core/TDCodecVia.cpp b/source/core/TDCodecVia.cpp index 9b9f464da..a6b72973a 100644 --- a/source/core/TDCodecVia.cpp +++ b/source/core/TDCodecVia.cpp @@ -1074,6 +1074,21 @@ Boolean TDViaParser::EatJSONItem(SubString* input) return true; } +bool IsInfinityOrNan(SubString token) +{ + bool isInfinityOrNan = false; + ConstCStr specialIEEEVals[] = { "infinity", "-infinity", "inf", "-inf", "nan", nullptr}; + ConstCStr* specValPtr = specialIEEEVals; + while (*specValPtr) { + if (token.ComparePrefixCStrIgnoreCase(*specValPtr)) { + isInfinityOrNan = true; + break; + } + ++specValPtr; + } + return isInfinityOrNan; +} + //------------------------------------------------------------ // ParseData - parse a value from the string based on the type // If the text makes sense then kNIError_Success is returned. @@ -1202,9 +1217,7 @@ Int32 TDViaParser::ParseData(TypeRef type, void* pData) TokenTraits tt = _string.ReadToken(&token, suppressInfNaN); token.TrimQuotedString(tt); Double value = 0.0; - Utf8Char leadingChar = token.StringLength() > 0 ? token.Begin()[0] : 0; - Boolean isMundane = (tt == TokenTraits_IEEE754 || tt == TokenTraits_Integer) && - (leadingChar == '.' || leadingChar == '-' || isdigit(leadingChar)); // not inf, nan + Boolean isMundane = (tt == TokenTraits_IEEE754 || tt == TokenTraits_Integer) && !IsInfinityOrNan(token); // not inf, nan Boolean readSuccess = token.ParseDouble(&value, suppressInfNaN, &errCode); if (!readSuccess) { if (_options._allowNulls && tt == TokenTraits_SymbolName && token.CompareCStr("null")) diff --git a/test-it/ExpectedResults/UnflattenJSONWithInfinity.vtr b/test-it/ExpectedResults/UnflattenJSONWithInfinity.vtr new file mode 100644 index 000000000..7abf3d539 --- /dev/null +++ b/test-it/ExpectedResults/UnflattenJSONWithInfinity.vtr @@ -0,0 +1,3 @@ +000 All tests pass: 'true'. +010 No error: 'true'. +020 Correct values: 'true'. diff --git a/test-it/ViaTests/UnflattenJSONWithInfinity.via b/test-it/ViaTests/UnflattenJSONWithInfinity.via new file mode 100644 index 000000000..887b62bcb --- /dev/null +++ b/test-it/ViaTests/UnflattenJSONWithInfinity.via @@ -0,0 +1,48 @@ +// Autogenerated Vireo assembly file +// Generated on 07/16/2024 14:20:22 +//--------------------------------------------------- +//VI Definition: ::VireoDevSystem::Interactive::WebApp::UnflattenJSONWithInfinity.gviweb +define (WebApp%3A%3AUnflattenJSONWithInfinity%2Egviweb dv(.VirtualInstrument ( + Locals: c( // Data Space + e(dv(.String 'WebApp::UnflattenJSONWithInfinity.gviweb')local0) + ce(dv(.ErrorCluster (false 0 '' ))c1) + ce(dv(.String '[1,2,-Infinity,inf,5]')c2) + ce(dv(a(.Double *) ())c3) + e(a(.Double *) local4) + e(.ErrorCluster local5) + e(.ErrorCluster local6) + e(.Int32 local7) + e(.Boolean local8) + de(dv(.Boolean false)dataItem_No_Error) + e(.Boolean local10) + ce(dv(a(.Double *) (1 2 -inf inf 5))c11) + e(.Boolean local12) + de(dv(.Boolean false)dataItem_CorrectValues) + e(.Boolean local14) + e(.Boolean local15) + de(dv(.Boolean false)dataItem_AllPass) + e(.Boolean local17) + e(a(.String *) local18) + e(dv(.Boolean true)local19) + e(dv(.Boolean false)local20) + e(dv(.Boolean false)local21) + ) + clump(1 + Copy(c1 local5) + Copy(c3 local4) + UnflattenFromJSON(c2 local4 local18 local19 local20 local21 local5 ) + Copy(local5 local6) + Copy(local6.code local7) + IsEQ0(local7 local8) + Copy(local8 dataItem_No_Error) + IsEQ(c11 local4 local12) + Copy(local12 dataItem_CorrectValues) + And(local12 local8 local15) + Copy(local15 dataItem_AllPass) + Printf ("000 All tests pass: '%s'.\n" dataItem_AllPass) + Printf ("010 No error: '%s'.\n" dataItem_No_Error) + Printf ("020 Correct values: '%s'.\n" dataItem_CorrectValues) +/* Clump Ended. */ ) +))) +enqueue (WebApp%3A%3AUnflattenJSONWithInfinity%2Egviweb) +//Finished!! :D diff --git a/test-it/testList.json b/test-it/testList.json index 1200b7542..f6cabe347 100644 --- a/test-it/testList.json +++ b/test-it/testList.json @@ -453,6 +453,7 @@ "UnflattenJSONNested.via", "UnflattenJSONPath.via", "UnflattenJSONStrict.via", + "UnflattenJSONWithInfinity.via", "UnflattenJSONWithNullValues.via", "UnflattenPathToIndex.via", "UnflattenStrictValidation.via",