From 5b8893114384652c3fd3631f676ba250d2cb9da6 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sun, 10 Nov 2013 14:50:35 -0600 Subject: [PATCH] Fixed bug while reading a single space char --- include/yaml-cpp/node/convert.h | 2 +- test/new-api/nodetests.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index d73f284..63ab9d7 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -89,7 +89,7 @@ namespace YAML const std::string& input = node.Scalar();\ std::stringstream stream(input);\ stream.unsetf(std::ios::dec);\ - if((stream >> rhs) && (stream >> std::ws).eof())\ + if((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof())\ return true;\ if(std::numeric_limits::has_infinity) {\ if(conversion::IsInfinity(input)) {\ diff --git a/test/new-api/nodetests.cpp b/test/new-api/nodetests.cpp index b002431..cb6a0c5 100644 --- a/test/new-api/nodetests.cpp +++ b/test/new-api/nodetests.cpp @@ -522,6 +522,13 @@ namespace Test YAML_ASSERT(std::string(emitter.c_str()) == ""); return true; } + + TEST SpaceChar() + { + YAML::Node node = YAML::Node(' '); + YAML_ASSERT(node.as() == ' '); + return true; + } } void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) { @@ -588,6 +595,7 @@ namespace Test RunNodeTest(&Node::DereferenceIteratorError, "dereference iterator error", passed, total); RunNodeTest(&Node::FloatingPrecision, "floating precision", passed, total); RunNodeTest(&Node::EmitEmptyNode, "emit empty node", passed, total); + RunNodeTest(&Node::SpaceChar, "space char", passed, total); std::cout << "Node tests: " << passed << "/" << total << " passed\n"; return passed == total;