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.
The YAML file is supposed to be well-formed because it comes right from RoR. The error seems to be triggered by this code:
formats: default: ! '%d-%m-%Y' long: ! '%d %B, %Y' short: ! '%d %b'
I'm not an expert, but I see from the YAML spec that you can use an exclamation mark to indicate a custom object/type, and two exclamation marks to indicate an explicit built-in type.
obj1: !custom # whatever obj2: !!str "My string"
However I haven't been able to find any reference to an exclamation mark used as above. What does that mean, and why the YAML library I use doesn't seem able to parse it? Note that if I remove those exclamation marks, the file is parsed fine.
Use quotes in YAML if your value includes special characters. For example, these special characters may require quotes: {, }, [, ], ,, &, :, *, #, ?, |. -, <. >, =, !, %, @, \. It is not necessary to use quotes when a single special character is surrounded by spaces, for example, * with spaces on both sides.
Strings in yaml only need quotation if (the beginning of) the value can be misinterpreted as a data type or the value contains a ":" (because it could get misinterpreted as key). needs quotes, because the value can be misinterpreted as key. and is a must, if working productively with yaml.
The native data structure in YAML includes simple representations such as nodes. It is also called as Representation Node Graph. It includes mapping, sequence and scalar quantities which is being serialized to create a serialization tree. With serialization the objects are converted with stream of bytes.
YAML syntaxYAML has features that come from Perl, C, XML, HTML, and other programming languages. YAML is also a superset of JSON, so JSON files are valid in YAML. YAML uses Python-style indentation to indicate nesting. Tab characters are not allowed, so whitespaces are used instead.
That !
is the non-specific tag.
The YAML specification 1.2 (as well as the previous 1.1) says that :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With