Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization of empty strings #489

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-24.04
steps:
- name: log github event
run: echo "${{toJSON(github.event)}}"
run: echo "${{toJSON(github.event)}}" || echo >/dev/null
check_workflows:
if: always()
continue-on-error: false
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/infra.ys
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
:: workflow-setup()

jobs:
log-github-event:
name: log github event
runs-on: ubuntu-24.04
steps:
- name: log github event
run: echo "${{toJSON(github.event)}}"
#log-github-event:
# name: log github event
# runs-on: ubuntu-24.04
# steps:
# - name: log github event
# run: echo "${{toJSON(github.event)}}" || echo >/dev/null

check_workflows:
:: setup-job('infra' 'check_workflows')
Expand Down
15 changes: 13 additions & 2 deletions changelog/current.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
## Fixes

- Fix [#480](https://github.com/biojppm/rapidyaml/issues/480) ([PR#489](https://github.com/biojppm/rapidyaml/pull/489)):
- Deserializing an empty quoted string *will not* cause an error.
- Deserializing an empty string *will* cause an error.
- Ensure keys are deserialized using all the rules applying to vals.
- Added `KEYNIL` and `VALNIL` to `NodeType_e`, used by the parser to mark the key or val as empty. This changed the values of the `NodeType_e` enumeration.
- Added `NodeType::key_is_null()` and `NodeType::val_is_null()`.
- [PR#488](https://github.com/biojppm/rapidyaml/pull/488):
- add workarounds for problems with codegen of gcc 11,12,13.
- improve CI coverage of gcc and clang optimization levels.
- [BREAKING] Fix [#477](https://github.com/biojppm/rapidyaml/issues/477): changed `read<std::map>()` to overwrite existing entries. The provided implementations had an inconsistency between `std::map` (which wasn't overwriting) and `std::vector` (which *was* overwriting).
- Fix [#475](https://github.com/biojppm/rapidyaml/issues/475): parse error on trailing whitespace in block containers.
- [BREAKING] Fix [#477](https://github.com/biojppm/rapidyaml/issues/477) ([PR#479](https://github.com/biojppm/rapidyaml/pull/479)): changed `read<std::map>()` to overwrite existing entries. The provided implementations had an inconsistency between `std::map` (which wasn't overwriting) and `std::vector` (which *was* overwriting).


## Thanks

- @Delian0
- @perlpunk
21 changes: 11 additions & 10 deletions src/c4/yml/emit.def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ void Emitter<Writer>::_emit_yaml(id_type id)
template<class Writer>
void Emitter<Writer>::_write_doc(id_type id)
{
RYML_ASSERT(m_tree->is_doc(id));
RYML_ASSERT(!m_tree->has_key(id));
const NodeType ty = m_tree->type(id);
RYML_ASSERT(ty.is_doc());
RYML_ASSERT(!ty.has_key());
if(!m_tree->is_root(id))
{
RYML_ASSERT(m_tree->is_stream(m_tree->parent(id)));
this->Writer::_do_write("---");
}
//
if(!m_tree->has_val(id)) // this is more frequent
if(!ty.has_val()) // this is more frequent
{
const bool tag = m_tree->has_val_tag(id);
const bool anchor = m_tree->has_val_anchor(id);
const bool tag = ty.has_val_tag();
const bool anchor = ty.has_val_anchor();
if(!tag && !anchor)
{
;
Expand Down Expand Up @@ -199,20 +200,20 @@ void Emitter<Writer>::_write_doc(id_type id)
}
else // docval
{
_RYML_CB_ASSERT(m_tree->callbacks(), m_tree->has_val(id));
_RYML_CB_ASSERT(m_tree->callbacks(), ty.has_val());
// some plain scalars such as '...' and '---' must not
// appear at 0-indentation
const csubstr val = m_tree->val(id);
const bool preceded_by_3_dashes = !m_tree->is_root(id);
const type_bits style_marks = m_tree->type(id) & (KEY_STYLE|VAL_STYLE);
const bool is_plain = m_tree->type(id).is_val_plain();
const type_bits style_marks = ty & VAL_STYLE;
const bool is_plain = ty.is_val_plain();
const bool is_ambiguous = (is_plain || !style_marks)
&& ((val.begins_with("...") || val.begins_with("---"))
||
(val.find('\n') != npos));
if(preceded_by_3_dashes)
{
if(val.len == 0 && !m_tree->has_val_anchor(id) && !m_tree->has_val_tag(id))
if(is_plain && val.len == 0 && !ty.has_val_anchor() && !ty.has_val_tag())
{
this->Writer::_do_write('\n');
return;
Expand Down Expand Up @@ -607,7 +608,7 @@ void Emitter<Writer>::_write(NodeScalar const& C4_RESTRICT sc, NodeType flags, i
}

// ensure the style flags only have one of KEY or VAL
_RYML_CB_ASSERT(m_tree->callbacks(), ((flags & SCALAR_STYLE) == 0) || (((flags&KEY_STYLE) == 0) != ((flags&VAL_STYLE) == 0)));
_RYML_CB_ASSERT(m_tree->callbacks(), ((flags & SCALAR_STYLE) == 0) || (((flags & KEY_STYLE) == 0) != ((flags & VAL_STYLE) == 0)));
type_bits style_marks = flags & SCALAR_STYLE;
if(!style_marks)
style_marks = scalar_style_choose(sc.scalar);
Expand Down
4 changes: 2 additions & 2 deletions src/c4/yml/emit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ inline OStream& operator<< (OStream& s, as_yaml const& y)
* @param id the node where to start emitting.
* @param opts emit options.
* @param buf the output buffer.
* @param opts emit options.
* @param error_on_excess Raise an error if the space in the buffer is insufficient.
* @return a substr trimmed to the result in the output buffer. If the buffer is
* insufficient (when error_on_excess is false), the string pointer of the
Expand All @@ -493,7 +492,6 @@ inline substr emit_yaml(Tree const& t, id_type id, substr buf, bool error_on_exc
* @param id the node where to start emitting.
* @param opts emit options.
* @param buf the output buffer.
* @param opts emit options.
* @param error_on_excess Raise an error if the space in the buffer is insufficient.
* @return a substr trimmed to the result in the output buffer. If the buffer is
* insufficient (when error_on_excess is false), the string pointer of the
Expand All @@ -515,6 +513,7 @@ inline substr emit_json(Tree const& t, id_type id, substr buf, bool error_on_exc

/** (1) emit YAML to the given buffer. Return a substr trimmed to the emitted YAML.
* @param t the tree; will be emitted from the root node.
* @param opts emit options.
* @param buf the output buffer.
* @param error_on_excess Raise an error if the space in the buffer is insufficient.
* @return a substr trimmed to the result in the output buffer. If the buffer is
Expand All @@ -533,6 +532,7 @@ inline substr emit_yaml(Tree const& t, substr buf, bool error_on_excess=true)
}
/** (1) emit JSON to the given buffer. Return a substr trimmed to the emitted JSON.
* @param t the tree; will be emitted from the root node.
* @param opts emit options.
* @param buf the output buffer.
* @param error_on_excess Raise an error if the space in the buffer is insufficient.
* @return a substr trimmed to the result in the output buffer. If the buffer is
Expand Down
13 changes: 13 additions & 0 deletions src/c4/yml/event_handler_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ struct EventHandlerTree : public EventHandlerStack<EventHandlerTree, EventHandle
/** @{ */


C4_ALWAYS_INLINE void set_key_scalar_plain_empty() noexcept
{
_c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
m_curr->tr_data->m_key.scalar = {};
_enable_(KEY|KEY_PLAIN|KEYNIL);
}
C4_ALWAYS_INLINE void set_val_scalar_plain_empty() noexcept
{
_c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
m_curr->tr_data->m_val.scalar = {};
_enable_(VAL|VAL_PLAIN|VALNIL);
}

C4_ALWAYS_INLINE void set_key_scalar_plain(csubstr scalar) noexcept
{
_c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
Expand Down
Loading
Loading