From 10b7bbcc29d442da41f0d3612895b7de2e57a152 Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Thu, 8 Aug 2024 10:20:07 +0200 Subject: [PATCH] fix parsing of val-less nested maps when deindented to maps re #455 --- changelog/current.md | 1 + src/c4/yml/parse_engine.def.hpp | 6 ++++ test/test_github_issues.cpp | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/changelog/current.md b/changelog/current.md index c8327e9e..08c4eb7e 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -1,5 +1,6 @@ ## Fixes +- Fix [#455](https://github.com/biojppm/rapidyaml/issues/455): parsing of trailing val-less nested maps when deindented to maps ([PR#460](https://github.com/biojppm/rapidyaml/pull/460)) - Fix filtering of double-quoted keys in block maps ([PR#452](https://github.com/biojppm/rapidyaml/pull/452)) - Fix [#440](https://github.com/biojppm/rapidyaml/issues/440): some tests failing with gcc -O2 (hypothetically due to undefined behavior) - This was accomplished by refactoring some internal parser functions; see the comments in [#440](https://github.com/biojppm/rapidyaml/issues/440) for further details. diff --git a/src/c4/yml/parse_engine.def.hpp b/src/c4/yml/parse_engine.def.hpp index 458b6c85..4e46040a 100644 --- a/src/c4/yml/parse_engine.def.hpp +++ b/src/c4/yml/parse_engine.def.hpp @@ -6338,6 +6338,12 @@ void ParseEngine::_handle_map_block() { _c4dbgp("mapblck[RVAL]: still mapblck!"); _line_progressed(m_evt_handler->m_curr->line_contents.indentation); + if(has_any(RNXT)) + { + _c4dbgp("mapblck[RVAL]: speculatively expect next keyval"); + m_evt_handler->add_sibling(); + addrem_flags(RKEY, RNXT); + } goto mapblck_again; } else diff --git a/test/test_github_issues.cpp b/test/test_github_issues.cpp index 6d44f0e3..bad0eee4 100644 --- a/test/test_github_issues.cpp +++ b/test/test_github_issues.cpp @@ -4,6 +4,67 @@ namespace c4 { namespace yml { +TEST(github, 455_0_ok) +{ + Tree t; + ExpectError::check_success([&t]{ + parse_in_arena(R"( + processors: + - simple: a + sampler: + trace_id_ratio_based: + ratio: +)", &t); + }); + ConstNodeRef sampler = t["sampler"]; + ASSERT_TRUE(sampler.is_map()); + ASSERT_TRUE(sampler.has_child("trace_id_ratio_based")); + ASSERT_TRUE(sampler["trace_id_ratio_based"].has_child("ratio")); +} + +TEST(github, 455_0) +{ + Tree t; + ExpectError::check_success([&t]{ + parse_in_arena(R"( + processors: + - simple: + sampler: + trace_id_ratio_based: + ratio: +)", &t); + }); + ConstNodeRef sampler = t["sampler"]; + ASSERT_TRUE(sampler.is_map()); + ASSERT_TRUE(sampler.has_child("trace_id_ratio_based")); + ASSERT_TRUE(sampler["trace_id_ratio_based"].has_child("ratio")); +} + +TEST(github, 455_1) +{ + Tree t; + ExpectError::check_success([&t]{ + parse_in_arena(R"( +file_format: 0.0 +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + trace_id_ratio_based: + ratio: + )", &t); + }); + ConstNodeRef sampler = t["tracer_provider"]["sampler"]; + ASSERT_TRUE(sampler.is_map()); + ASSERT_TRUE(sampler.has_child("trace_id_ratio_based")); + ASSERT_TRUE(sampler["trace_id_ratio_based"].has_child("ratio")); +} + + +//----------------------------------------------------------------------------- + TEST(github, 268) { Tree tree = parse_in_arena(R"(