fktn-k / fkYAML

A C++ header-only YAML library
MIT License
69 stars 7 forks source link

Embedded flow indicators in plain unquoted scalar values cause incorrect parse results #292

Closed stephenwhittle closed 6 months ago

stephenwhittle commented 6 months ago

Description

This issue is similar to #275 , but concerns values rather than keys. A flow sequence or mapping indicator is currently treated by the parser as the end of a plain unquoted scalar value, even outside of a flow collection.

Reproduction steps

The following minimal YAML demonstrates the issue:

KEY:
          description: Cryptographic key, bits [159 :128]

Expected vs. actual results

The entire string Cryptographic key, bits [159 :128] should be treated as the value, but because the lexer treats [ as the end of a string, the resulting tree contains a key of 159 and a value of 128 with the rest of the string being discarded.

In my testing, checking m_flow_context_depth before treating those indicators as string terminators in the lexer, seems to address this issue.

Minimal code example

No response

Error messages

No response

Compiler and operating system

VS 2022 (both clang-cl and msvc compilers), Win 10

Library version

04e1a7b9115398ae8c57c0f5263dcb8390e3dc32

Validation

fktn-k commented 6 months ago

@stephenwhittle
Thanks for the bug report!
I overlooked that part while fixing the issue you referred in the description.

Also, I totally agree with your solution and thanks again for the PR.
I'll take a look soon.