Repository: mesos Updated Branches: refs/heads/master 8d53a932b -> 62f7a27fe
Fixed printing of numbers to be valid JSON for web browsers. Printing an integer as a double looked like "1." which is an "unterminated fractional number". Instead, the printed value should be "1.0". Review: https://reviews.apache.org/r/38632 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/62f7a27f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/62f7a27f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/62f7a27f Branch: refs/heads/master Commit: 62f7a27fe618c67950c7a651529ff809d4a7222d Parents: 8d53a93 Author: Joseph Wu <[email protected]> Authored: Tue Sep 22 13:50:47 2015 -0400 Committer: Joris Van Remoortere <[email protected]> Committed: Tue Sep 22 14:18:07 2015 -0400 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/json.hpp | 6 ++++-- .../libprocess/3rdparty/stout/tests/json_tests.cpp | 6 +++--- .../3rdparty/stout/tests/protobuf_tests.cpp | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/62f7a27f/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp index e36f4b9..0870300 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp @@ -633,9 +633,11 @@ inline std::ostream& operator<<(std::ostream& out, const Number& number) std::numeric_limits<double>::digits10, number.value); - // Get rid of trailing zeroes before outputting. + // Get rid of excess trailing zeroes before outputting. // Otherwise, printing 1.0 would result in "1.00000000000000". - return out << strings::trim(buffer, strings::SUFFIX, "0"); + // NOTE: valid JSON numbers cannot end with a '.'. + std::string trimmed = strings::trim(buffer, strings::SUFFIX, "0"); + return out << trimmed << (trimmed.back() == '.' ? "0" : ""); } case Number::SIGNED_INTEGER: return out << number.signed_integer; http://git-wip-us.apache.org/repos/asf/mesos/blob/62f7a27f/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp index 88b6147..131d39b 100644 --- a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp +++ b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp @@ -51,11 +51,11 @@ TEST(JsonTest, BinaryData) TEST(JsonTest, NumberFormat) { // Test whole numbers (as doubles). - EXPECT_EQ("0.", stringify(JSON::Number(0.0))); - EXPECT_EQ("1.", stringify(JSON::Number(1.0))); + EXPECT_EQ("0.0", stringify(JSON::Number(0.0))); + EXPECT_EQ("1.0", stringify(JSON::Number(1.0))); // Negative. - EXPECT_EQ("-1.", stringify(JSON::Number(-1.0))); + EXPECT_EQ("-1.0", stringify(JSON::Number(-1.0))); // Test integers. EXPECT_EQ("0", stringify(JSON::Number(0))); http://git-wip-us.apache.org/repos/asf/mesos/blob/62f7a27f/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp index 6f154cd..68328a2 100644 --- a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp +++ b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp @@ -108,18 +108,18 @@ TEST(ProtobufTest, JSON) "{" " \"b\": true," " \"bytes\": \"Ynl0ZXM=\"," - " \"d\": 1.," + " \"d\": 1.0," " \"e\": \"ONE\"," - " \"f\": 1.," + " \"f\": 1.0," " \"int32\": -1," " \"int64\": -1," " \"nested\": { \"str\": \"nested\"}," - " \"optional_default\": 42.," + " \"optional_default\": 42.0," " \"repeated_bool\": [true]," " \"repeated_bytes\": [\"cmVwZWF0ZWRfYnl0ZXM=\"]," - " \"repeated_double\": [1., 2.]," + " \"repeated_double\": [1.0, 2.0]," " \"repeated_enum\": [\"TWO\"]," - " \"repeated_float\": [1.]," + " \"repeated_float\": [1.0]," " \"repeated_int32\": [-2]," " \"repeated_int64\": [-2]," " \"repeated_nested\": [ { \"str\": \"repeated_nested\" } ]," @@ -196,13 +196,13 @@ TEST(ProtobufTest, JsonLargeIntegers) "{" " \"b\": true," " \"bytes\": \"Ynl0ZXM=\"," - " \"d\": 1.," + " \"d\": 1.0," " \"e\": \"ONE\"," - " \"f\": 1.," + " \"f\": 1.0," " \"int32\": -2147483647," " \"int64\": -9223372036854775807," " \"nested\": {\"str\": \"nested\"}," - " \"optional_default\": 42.," + " \"optional_default\": 42.0," " \"repeated_int32\": [-2000000000]," " \"repeated_int64\": [-9000000000000000000]," " \"repeated_sint32\": [-1000000000],"
