Commit 5b8183c1 authored by Nima Aghdaii's avatar Nima Aghdaii Committed by facebook-github-bot-1

Fix Infinity

Summary: folly only accepts "Infinity" while deserializing but writes "infinity" when serializing.
This means folly cannot deserialize what it serialized before.
If we agree on this, we could update ##fbcode/common## as well: https://fburl.com/136793901

Reviewed By: @marcinpe

Differential Revision: D2293627
parent b8aa5fcd
......@@ -636,7 +636,7 @@ toAppend(
using namespace double_conversion;
DoubleToStringConverter
conv(DoubleToStringConverter::NO_FLAGS,
"infinity", "NaN", 'E',
"Infinity", "NaN", 'E',
detail::kConvMaxDecimalInShortestLow,
detail::kConvMaxDecimalInShortestHigh,
6, // max leading padding zeros
......
......@@ -77,7 +77,10 @@ TEST(Json, Parse) {
// case matters
EXPECT_THROW(parseJson("infinity"), std::runtime_error);
EXPECT_THROW(parseJson("inf"), std::runtime_error);
EXPECT_THROW(parseJson("Inf"), std::runtime_error);
EXPECT_THROW(parseJson("INF"), std::runtime_error);
EXPECT_THROW(parseJson("nan"), std::runtime_error);
EXPECT_THROW(parseJson("NAN"), std::runtime_error);
auto array = parseJson(
"[12,false, false , null , [12e4,32, [], 12]]");
......@@ -169,6 +172,14 @@ TEST(Json, Produce) {
// We're not allowed to have non-string keys in json.
EXPECT_THROW(toJson(dynamic::object("abc", "xyz")(42.33, "asd")),
std::runtime_error);
// Check Infinity/Nan
folly::json::serialization_opts opts;
opts.allow_nan_inf = true;
EXPECT_EQ("Infinity",
folly::json::serialize(parseJson("Infinity"), opts).toStdString());
EXPECT_EQ("NaN",
folly::json::serialize(parseJson("NaN"), opts).toStdString());
}
TEST(Json, JsonEscape) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment