fktn-k / fkYAML

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

Parse error on an alias node key #302

Closed fktn-k closed 6 months ago

fktn-k commented 6 months ago

Description

If the input contains an alias node as a mapping key, the parser will produce a parse error. (See the YAML snippet in the Reproduction steps for an example.)
This is because the lexer doesn't consider alias mapping key and assumes that there is a space or a newline code at the end of an alias label.
And since the given alias label doesn't match any of existing anchor labels, the parser will produce a parse error.

Furthermore, the parser also assumes the alias node is a mapping/sequence value.
So, both the lexer and the parser must be modified to ensure that the alias mapping key is correctly parsed.

Reproduction steps

Try parse the following YAML snippet:

&anchor foo:
  *anchor: 123

Expected vs. actual results

The parser must not emit any error for the above YAML snippet, but it actually does.

Minimal code example

#include <iostream>
#include <fkYAML/node.hpp>

int main()
{
    fkyaml::node node = fkyaml::node::deserialize("&anchor foo:\n  *anchor: 123");
}

Error messages

parse_error: The given anchor name must appear prior to the alias node. (atline 1, column 2)

Compiler and operating system

GCC 11.4.0 & Clang 14.0.0 on Ubuntu 22.04 LTS

Library version

develop HEAD

Validation