What does a single exclamation mark do in YAML?

后端 未结 1 797

I\'m working with the YamlDotNet library and I\'m getting this error when loading a YAML file:

While parsing a tag, did not find expected tag URI.

相关标签:
1条回答
  • 2020-12-05 10:09

    That "!" is the "non-specific tag".

    YAML specification 1.2 stays (also 1.1):

    By explicitly specifying a “!” non-specific tag property, the node would then be resolved to a “vanilla” sequence, mapping, or string, according to its kind.

    Take a look here to the tag "grammar":

    none    : Unspecified tag (automatically resolved by application).
    '!'     : Non-specific tag (by default, "!!map"/"!!seq"/"!!str").
    '!foo'  : Primary (by convention, means a local "!foo" tag).
    '!!foo' : Secondary (by convention, means "tag:yaml.org,2002:foo").
    '!h!foo': Requires "%TAG !h! <prefix>" (and then means "<prefix>foo").
    '!<foo>': Verbatim tag (always means "foo").
    

    Why is YamlDotNet throwing a error? I can't be 100% sure, but I think you found a bug.

    YamlDotNet is a port of LibYAML, so it's easy to compare sources.

    Line 2635 of scanner.c (LibYAML):

    /* Check if the tag is non-empty. */
    if (!length) {
    

    Line 2146 of Scanner.cs (YamlDotNet ):

    // Check if the tag is non-empty.
    if (tag.Length == 0)
    

    I know, both looks very similar, but at this point length is 1 and tag.Length is 0. Original C code takes care of the initial "!" (whole length) but C# doesn't do it (just the tag "name" length).

    File an issue to the project.

    0 讨论(0)
提交回复
热议问题