mirror of
https://github.com/biojppm/rapidyaml.git
synced 2026-01-18 13:31:19 +01:00
[wip fix] ensure parse error on empty block scalars with missing chomp or 0 indentation
This commit is contained in:
@@ -12,19 +12,33 @@
|
||||
:barbar: b # was ok
|
||||
:barbarbar: c # was ol
|
||||
```
|
||||
- Maps: ensure parse error on keyless trailing scalars:
|
||||
```yaml
|
||||
--- # test suite case 236B
|
||||
foo:
|
||||
bar
|
||||
invalid
|
||||
--- # test suite case 7MNF
|
||||
top1:
|
||||
key1: val1
|
||||
top2
|
||||
--- # test suite case 9CWY
|
||||
key:
|
||||
- item1
|
||||
- item2
|
||||
invalid
|
||||
```
|
||||
- Scalars:
|
||||
- Do not accept block scalars with 0 indentation:
|
||||
```yaml
|
||||
# test suite case 2G84
|
||||
--- |0 # error
|
||||
--- |10 # error
|
||||
--- |1- # ok
|
||||
--- |1+ # ok
|
||||
```
|
||||
- Maps
|
||||
- ensure parse error on keyless terminating scalars:
|
||||
```yaml
|
||||
---
|
||||
foo:
|
||||
bar
|
||||
valid: # ok
|
||||
--- # test suite case 236B
|
||||
foo:
|
||||
bar
|
||||
invalid # parse error expected
|
||||
--- # test suite case 7MNF
|
||||
top1:
|
||||
key1: val1
|
||||
invalid # parse error expected
|
||||
--- # test suite case 9CWY
|
||||
key:
|
||||
- item1
|
||||
- item2
|
||||
invalid # parse error expected
|
||||
```
|
||||
|
||||
@@ -4003,6 +4003,7 @@ csubstr Parser::_scan_block()
|
||||
BlockStyle_e newline = s.begins_with('>') ? BLOCK_FOLD : BLOCK_LITERAL;
|
||||
BlockChomp_e chomp = CHOMP_CLIP; // default to clip unless + or - are used
|
||||
size_t indentation = npos; // have to find out if no spec is given
|
||||
bool explicit_chomp = false;
|
||||
csubstr digits;
|
||||
if(s.len > 1)
|
||||
{
|
||||
@@ -4014,6 +4015,7 @@ csubstr Parser::_scan_block()
|
||||
_c4dbgpf("scanning block: spec chomp char at {}", pos);
|
||||
if(pos != npos)
|
||||
{
|
||||
explicit_chomp = true;
|
||||
if(t[pos] == '-')
|
||||
chomp = CHOMP_STRIP;
|
||||
else if(t[pos] == '+')
|
||||
@@ -4028,7 +4030,9 @@ csubstr Parser::_scan_block()
|
||||
if( ! digits.empty())
|
||||
{
|
||||
if( ! c4::atou(digits, &indentation))
|
||||
_c4err("parse error: could not read decimal");
|
||||
_c4err("could not read block scalar indentation");
|
||||
if( ! indentation)
|
||||
_c4err("invalid block scalar indentation");
|
||||
_c4dbgpf("scanning block: indentation specified: {}. add {} from curr state -> {}", indentation, m_state->indref, indentation+m_state->indref);
|
||||
indentation += m_state->indref;
|
||||
}
|
||||
@@ -4160,7 +4164,6 @@ csubstr Parser::_scan_block()
|
||||
++num_lines;
|
||||
}
|
||||
_RYML_CB_ASSERT(m_stack.m_callbacks, m_state->pos.line == (first + num_lines));
|
||||
C4_UNUSED(num_lines);
|
||||
C4_UNUSED(first);
|
||||
|
||||
if(indentation == npos)
|
||||
@@ -4171,6 +4174,8 @@ csubstr Parser::_scan_block()
|
||||
|
||||
if(num_lines)
|
||||
_line_ended_undo();
|
||||
else if(!explicit_chomp)
|
||||
_c4err("block scalars must not be empty");
|
||||
|
||||
_c4dbgpf("scanning block: raw=~~~{}~~~", raw_block);
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ constexpr const AllowedFailure allowed_failures[] = {
|
||||
_("Y79Y_004-error", "should not accept tab after -"),
|
||||
_("Y79Y_005-error", "should not accept tab after -"),
|
||||
// block scalars
|
||||
_("2G84_00-error" , "should not accept the block literal spec"),
|
||||
_("2G84_01-error" , "should not accept the block literal spec"),
|
||||
_("5LLU-error" , "should not accept folded scalar with wrong indented line after spaces only"),
|
||||
_("S4GJ-error" , "should not accept text after block scalar indicator"),
|
||||
_("S98Z-error" , "should not accept block scalar with more spaces than first content line"),
|
||||
@@ -112,7 +110,8 @@ constexpr const AllowedFailure allowed_failures[] = {
|
||||
// These tests are skipped because they cover parts of YAML that
|
||||
// are deliberately not implemented by ryml.
|
||||
|
||||
#ifndef RYML_WITH_TAB_TOKENS // -<tab> or :<tab> are supported only when the above macro is defined
|
||||
// -<tab> or :<tab> are supported only when the above macro is defined
|
||||
#ifndef RYML_WITH_TAB_TOKENS
|
||||
_("A2M4-in_yaml-events" , "tabs tokens"),
|
||||
_("6BCT-in_yaml" , "tabs tokens"),
|
||||
_("J3BT-in_yaml" , "tabs tokens"),
|
||||
|
||||
Reference in New Issue
Block a user