fix issue917: handle the trailing TAB of block scalar

This commit is contained in:
dota17 2020-07-14 21:03:33 +08:00
parent c82d3129dd
commit 942da73ed5
2 changed files with 6 additions and 1 deletions

View File

@ -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;

View File

@ -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);