[fix] re #361: fix parse of scalars with : and starting on the next line

This commit is contained in:
Joao Paulo Magalhaes
2023-06-06 09:05:12 +01:00
parent 0e864cb3f0
commit f18e71138e
3 changed files with 90 additions and 7 deletions

View File

@@ -1,6 +1,16 @@
### Fixes
- Fix [#361](https://github.com/biojppm/rapidyaml/pull/361) - parse error on map scalars containing `:` and starting on the next line:
```yaml
---
# failed to parse:
description:
foo:bar
---
# but this was ok:
description: foo:bar
```
- [PR#368](https://github.com/biojppm/rapidyaml/pull/368) - fix pedantic compiler warnings.
- Fix [#373](https://github.com/biojppm/rapidyaml/issues/373) - false parse error with empty quoted keys in block-style map ([PR#374](https://github.com/biojppm/rapidyaml/pull/374)).
- Fix [#356](https://github.com/biojppm/rapidyaml/issues/356) - fix overzealous check in `emit_as()`. An id may be larger than the tree's size, eg when nodes were removed.

View File

@@ -2784,20 +2784,34 @@ bool Parser::_scan_scalar_unk(csubstr *C4_RESTRICT scalar, bool *C4_RESTRICT quo
}
size_t pos = s.find(" #");
if(pos != npos)
{
_c4dbgpf("RUNK: found ' #' at {}", pos);
s = s.left_of(pos);
}
pos = s.find(": ");
if(pos != npos)
{
_c4dbgpf("RUNK: found ': ' at {}", pos);
s = s.left_of(pos);
}
else if(s.ends_with(':'))
{
_c4dbgp("RUNK: ends with ':'");
s = s.left_of(s.len-1);
}
_RYML_WITH_TAB_TOKENS(
else if((pos = s.find(":\t")) != npos) // TABS
{
_c4dbgp("RUNK: ends with ':\\t'");
s = s.left_of(pos);
)
})
else
{
_c4dbgp("RUNK: trimming left of ,");
s = s.left_of(s.first_of(','));
}
s = s.trim(" \t");
_c4dbgpf("RUNK: scalar='{}'", s);
_c4dbgpf("RUNK: scalar=[{}]~~~{}~~~", s.len, s);
if(s.empty())
return false;
@@ -2808,11 +2822,11 @@ bool Parser::_scan_scalar_unk(csubstr *C4_RESTRICT scalar, bool *C4_RESTRICT quo
if(_at_line_end() && s != '~')
{
_c4dbgpf("at line end. curr='{}'", s);
_c4dbgpf("at line end. curr=[{}]~~~{}~~", s.len, s);
s = _extend_scanned_scalar(s);
}
_c4dbgpf("scalar was '{}'", s);
_c4dbgpf("scalar was [{}]~~~{}~~~", s.len, s);
*scalar = s;
*quoted = false;
@@ -4046,7 +4060,7 @@ bool Parser::_handle_indentation()
_RYML_CB_ASSERT(m_stack.m_callbacks, ind > m_state->indref);
if(has_all(RMAP|RVAL))
{
if(_is_scalar_next__rmap_val(remt) && remt.first_of(":?") == npos)
if(_is_scalar_next__rmap_val(remt) && (!remt.first_of_any(": ", "? ")) && (!remt.ends_with(":")))
{
_c4dbgpf("actually it seems a value: '{}'", remt);
}

View File

@@ -3,6 +3,66 @@
namespace c4 {
namespace yml {
TEST(simple_map, issue361)
{
{
const Tree t = parse_in_arena(R"(desc: foo bar)");
ASSERT_EQ(t["desc"].val(), "foo bar");
}
//
{
const Tree t = parse_in_arena(R"(desc:
foo bar)");
ASSERT_EQ(t["desc"].val(), "foo bar");
}
//
{
const Tree t = parse_in_arena(R"(desc: foo:bar)");
ASSERT_EQ(t["desc"].val(), "foo:bar");
}
//
{
const Tree t = parse_in_arena(R"(desc:
foo:bar)");
ASSERT_EQ(t["desc"].val(), "foo:bar");
}
//
{
const Tree t = parse_in_arena(R"(desc: Timecode in "HH:MM:SS:FF" format where the last ':' can be replaced by ',' or ';'.)");
ASSERT_EQ(t["desc"].val(), "Timecode in \"HH:MM:SS:FF\" format where the last ':' can be replaced by ',' or ';'.");
}
//
{
const Tree t = parse_in_arena(R"(desc:
Timecode in "HH:MM:SS:FF" format where the last ':' can be replaced by ',' or ';'.)");
ASSERT_EQ(t["desc"].val(), "Timecode in \"HH:MM:SS:FF\" format where the last ':' can be replaced by ',' or ';'.");
}
//
{
const Tree t = parse_in_arena(R"(value:
desc:
Timecode in "HH:MM:SS:FF" format where the last ':' can be replaced by ',' or ';'.)");
ASSERT_EQ(t["value"]["desc"].val(), "Timecode in \"HH:MM:SS:FF\" format where the last ':' can be replaced by ',' or ';'.");
}
}
TEST(simple_map, issue377)
{
csubstr yaml = R"(
const game::perception::PerceiveData:
PerceiveData: {default: nullptr}
)";
test_check_emit_check(yaml, [](Tree const &t){
ASSERT_TRUE(t.rootref().has_child("const game::perception::PerceiveData"));
const ConstNodeRef cpd = t["const game::perception::PerceiveData"];
ASSERT_TRUE(cpd.is_map());
ASSERT_TRUE(cpd.has_child("PerceiveData"));
ASSERT_EQ(cpd["PerceiveData"].num_children(), 1u);
ASSERT_TRUE(cpd["PerceiveData"].has_child("default"));
ASSERT_EQ(cpd["PerceiveData"]["default"].val(), "nullptr");
});
}
TEST(simple_map, issue373)
{
{
@@ -833,8 +893,7 @@ h3 ,i3: val3 ,0003
})",
L{ // this is crazy...
N(KEYVAL, "a0", /*"~"*/{}),
N("b0", "val0"),
N(KEYVAL, "0000 c0", /*"~"*/{}),
N("b0", "val0"), N(KEYVAL, "0000 c0", /*"~"*/{}),
N("d0", "val0"), N(KEYVAL, "0000 e0", /*"~"*/{}),
N("f0", "val0"), N(KEYVAL, "0000 h0", /*"~"*/{}),
N("i0", "val0"), N(KEYVAL, "0000 a1", /*"~"*/{}),