From 71dd6583254dc9fd6c210c2bafd0936f85c6ab6f Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 22 Apr 2016 15:52:40 -0700 Subject: [PATCH] Fix write_json non-pretty print extra endl According to bug #12149, the non-pretty version of write_json should not print the trailing endl. This patch only prints the endl in the pretty case, and only does the flush component of the endl in the non-pretty version. Signed-off-by: Erich Keane --- include/boost/property_tree/json_parser/detail/write.hpp | 5 ++++- test/test_json_parser.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/boost/property_tree/json_parser/detail/write.hpp b/include/boost/property_tree/json_parser/detail/write.hpp index b8ef7eb664..db89b29e6e 100644 --- a/include/boost/property_tree/json_parser/detail/write.hpp +++ b/include/boost/property_tree/json_parser/detail/write.hpp @@ -158,7 +158,10 @@ namespace boost { namespace property_tree { namespace json_parser if (!verify_json(pt, 0)) BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0)); write_json_helper(stream, pt, 0, pretty); - stream << std::endl; // outputting endl performs flush + + if (pretty) stream << std::endl; + else stream << std::flush; + if (!stream.good()) BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0)); } diff --git a/test/test_json_parser.cpp b/test/test_json_parser.cpp index 6a6ddd24a2..e856a3d3e6 100644 --- a/test/test_json_parser.cpp +++ b/test/test_json_parser.cpp @@ -257,7 +257,7 @@ const char *bug_data_pr7180_1 = " ]\n" "}\n"; const char *bug_data_pr7180_2 = - "{\"a\":[\"1\",\"2\"]}\n"; + "{\"a\":[\"1\",\"2\"]}"; struct ReadFunc {