Skip to content

Handle empty mapping key separator as parse error#525

Merged
fktn-k merged 3 commits into
fktn-k:developfrom
sndth:issue-514-malformed-yaml
Jul 7, 2026
Merged

Handle empty mapping key separator as parse error#525
fktn-k merged 3 commits into
fktn-k:developfrom
sndth:issue-514-malformed-yaml

Conversation

@sndth

@sndth sndth commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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 a KEY_SEPARATOR token. For malformed input such as:

: foo

the 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_error when 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:


Pull Request Checklist

Read the CONTRIBUTING.md file for detailed information.

  • Changes are described in the pull request or in a referenced issue.
  • The test suite compiles and runs without any error.
  • The code coverage on your branch is 100%.
  • The documentation is updated if you added/changed a feature.

Please don't

  • The C++11 support varies between different compilers and versions. Please note the list of supported compilers. Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with #ifdefs or other means.
  • Please refrain from proposing changes that would break YAML specifications. If you propose a conformant extension of YAML to be supported by the library, please motivate this extension.
  • Please do not open pull requests that address multiple issues.

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.
@sndth sndth requested a review from fktn-k as a code owner July 6, 2026 18:29
@sndth sndth changed the title Handle empty mapping key separator as parse error (issue #514) Handle empty mapping key separator as parse error Jul 6, 2026
@coveralls

coveralls commented Jul 6, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28893909149

Coverage decreased (-0.03%) to 99.939%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (12 of 13 lines covered, 92.31%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
include/fkYAML/detail/input/deserializer.hpp 13 12 92.31%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 5154
Covered Lines: 5152
Line Coverage: 99.96%
Relevant Branches: 1404
Covered Branches: 1402
Branch Coverage: 99.86%
Branches in Coverage %: Yes
Coverage Strength: 403.52 hits per line

💛 - Coveralls

Comment thread include/fkYAML/detail/input/deserializer.hpp Outdated
sndth added 2 commits July 7, 2026 09:21
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.

@fktn-k fktn-k left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sndth
Looks good to me. Thanks!

@fktn-k fktn-k merged commit bb458b0 into fktn-k:develop Jul 7, 2026
186 of 187 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants