Handle empty mapping key separator as parse error#525
Merged
Conversation
Replace an assertion-only guard in KEY_SEPARATOR handling with a parse_error when the parser sees a mapping value separator without an active context. This prevents malformed input such as `: foo` from aborting on FK_YAML_ASSERT(!m_context_stack.empty()) and lets callers handle the failure through the normal exception path. Add regression coverage for the empty-key separator case and for the issue fktn-k#514 input to ensure it does not abort during deserialization.
Coverage Report for CI Build 28893909149Coverage decreased (-0.03%) to 99.939%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
fktn-k
requested changes
Jul 7, 2026
Parse a root-level mapping value separator as an empty string key instead of throwing a parse_error. This supports YAML such as `: foo` as a mapping with `""` as the key, while leaving empty mapping keys inside block sequences unsupported for now. Update the key separator regression tests accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a defensive fix for malformed mapping key separators.
The deserializer previously relied on
FK_YAML_ASSERT(!m_context_stack.empty())when handling aKEY_SEPARATORtoken. For malformed input such as:: foothe context stack can be empty, causing the process to abort instead of throwing a catchable exception.
This change replaces that assertion-only guard with a
parse_errorwhen a key separator is encountered without an active parsing context. This keeps malformed input on the normal error handling path and lets callers catch the failure.I could not reproduce the exact assertion failure from issue #514 locally with:
"\"\":\n port:not_a_scalar]\n"On my environment, that input is parsed as a mapping with an empty string key and a plain scalar value. I still added regression coverage for it to ensure deserialization does not abort.
Added regression coverage for:
: foo) throwingparse_errorPull Request Checklist
Read the CONTRIBUTING.md file for detailed information.
Please don't
#ifdefs or other means.