From c3df6d87d42ed0f4b047405a558b9850ff7b888e Mon Sep 17 00:00:00 2001 From: Chen Date: Thu, 16 Jul 2020 23:08:09 +0800 Subject: [PATCH] Properly allow a trailing tab character on a block scalar (#919) Fixes #917 --- src/scanscalar.cpp | 2 +- test/integration/load_node_test.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/scanscalar.cpp b/src/scanscalar.cpp index 0a47a46..be57b1c 100644 --- a/src/scanscalar.cpp +++ b/src/scanscalar.cpp @@ -204,7 +204,7 @@ std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) { // post-processing if (params.trimTrailingSpaces) { - std::size_t pos = scalar.find_last_not_of(' '); + std::size_t pos = scalar.find_last_not_of(" \t"); if (lastEscapedChar != std::string::npos) { if (pos < lastEscapedChar || pos == std::string::npos) { pos = lastEscapedChar; diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index d0bbd4b..958e735 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -284,6 +284,11 @@ TEST(NodeTest, SpecialFlow) { {"{:a}", NodeType::Map, 1, "{:a: ~}"}, {"{,}", NodeType::Map, 1, "{~: ~}"}, {"{a:,}", NodeType::Map, 1, "{a: ~}"}, + //testcase for the trailing TAB of scalar + {"key\t: value\t", NodeType::Map, 1, "key: value"}, + {"key\t: value\t #comment", NodeType::Map, 1, "key: value"}, + {"{key\t: value\t}", NodeType::Map, 1, "{key: value}"}, + {"{key\t: value\t #comment\n}", NodeType::Map, 1, "{key: value}"}, }; for (const SingleNodeTestCase& test : tests) { Node node = Load(test.input);