Scene files: Invalid YAML?

Hi there,

as pointed out in Smart Merge not working - Unity Engine - Unity Discussions, Unity adds the keyword “stripped” after the object identifier/document boundary marker in the scene files.

As far as I understand this does not match the YAML specifications and hence is invalid YAML - according to: YAML Ain’t Markup Language (YAML™) Version 1.1 boundary marker/.

All standard YAML parsers fail to parse scene files which contain a “stripped” keyword near to the document boundary - resulting in a “mapping values are not allowed in this context” exception.

Test case:
Enter this in http://www.yamllint.com/ and try to parse it by clicking “Go”.

Also tested with YamlDotNet from GitHub - aaubry/YamlDotNet: YamlDotNet is a .NET library for YAML, which supports multi-document streams with this patch: Re-implementing Parser: Add support for multi-document tag directives by derFunk · Pull Request #142 · aaubry/YamlDotNet · GitHub.

Any suggestions? Shouldn’t you stick to the standard specifications? Or am I just missing something?

1 Like

Bumped into the same problem too.

Same problem here. I’m trying to read Unity’s serialized asset data outside of the context of Unity, and the Yaml parser (YamlDotNet) fails when it encounters the “stripped” string.

Is there a yaml parser which allows this syntax?

Ran into the same problem here. What’s the point of using a ‘standard’ file format if you break it so no standard parser can read it?

1 Like

Bit hacky, but I did this…

string wholeFile = File.ReadAllText(file);
wholeFile = Regex.Replace(wholeFile, "([0-9]+ &[0-9]+) stripped\n", "$1\n");

using (var reader = new StringReader(wholeFile))
{
    var yaml = new YamlStream();
    try
    {
        yaml.Load(reader);
    }
    catch { }
    ....

You are a dirty, dirty boy.

Also you get a cookie :smile:

Apologies for bumping this old thread

Anyone got around to a better solution other than removing the “stripped” thing? I’m using libyaml event based parsing, already had to modify it to make document tags optional and so far only “stripped” classes are breaking it

Hi. I recently implemented a fast YAML parser in C#.
This parser supports parsing Unity’s stripped malformed YAML.

Give it a try if you like.

var collection = Yamlserializer.DeserializeMultipleDocuments<dynamic>(yamlBytes)
1 Like