YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

Empty key is throwing an exception

Open zwcloud opened this issue 2 years ago • 6 comments

Here is a meta file created by Unity for a managed dll:

fileFormatVersion: 2
guid: 29e75658b79a414a8525c35535b64f6c
PluginImporter:
  externalObjects: {}
  serializedVersion: 2
  iconMap: {}
  executionOrder: {}
  defineConstraints: []
  isPreloaded: 0
  isOverridable: 0
  isExplicitlyReferenced: 0
  validateReferences: 0
  platformData:
  - first:
      : Any
    second:
      enabled: 0
      settings:
        Exclude Android: 1
        Exclude Editor: 0
        Exclude Linux: 1
        Exclude Linux64: 1
        Exclude LinuxUniversal: 1
        Exclude OSXUniversal: 1
        Exclude Win: 1
        Exclude Win64: 1
  - first:
      Android: Android
    second:
      enabled: 0
      settings:
        CPU: ARMv7
  - first:
      Any: 
    second:
      enabled: 1
      settings: {}
  - first:
      Editor: Editor
    second:
      enabled: 1
      settings:
        CPU: AnyCPU
        DefaultValueInitialized: true
        OS: AnyOS
  - first:
      Facebook: Win
    second:
      enabled: 0
      settings:
        CPU: AnyCPU
  - first:
      Facebook: Win64
    second:
      enabled: 0
      settings:
        CPU: AnyCPU
  - first:
      Standalone: Linux
    second:
      enabled: 0
      settings:
        CPU: x86
  - first:
      Standalone: Linux64
    second:
      enabled: 0
      settings:
        CPU: None
  - first:
      Standalone: OSXUniversal
    second:
      enabled: 0
      settings:
        CPU: None
  - first:
      Standalone: Win
    second:
      enabled: 0
      settings:
        CPU: None
  - first:
      Standalone: Win64
    second:
      enabled: 0
      settings:
        CPU: None
  - first:
      Windows Store Apps: WindowsStoreApps
    second:
      enabled: 0
      settings:
        CPU: AnyCPU
  userData: 
  assetBundleName: 
  assetBundleVariant: 

Note this line : Any. It doesn't contain a valid key.

  platformData:
  - first:
      : Any
    second:

This is incorrect but Unity output this. So is it possible to safely ignore this line? Where is the code handling this? I'm willing to create a PR to support this.

BTW, this causes a ArgumentException here:

Issue with input parameters : System.ArgumentException: The current event is of an unsupported type. (Parameter 'parser')
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlSequenceNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlMappingNode.Load(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlNode.ParseNode(IParser parser, DocumentLoadingState state)
   at YamlDotNet.RepresentationModel.YamlDocument..ctor(IParser parser)
   at YamlDotNet.RepresentationModel.YamlStream.Load(IParser parser)

zwcloud avatar Feb 07 '23 14:02 zwcloud

The issue may be in the scanner. Probably around here.

https://github.com/aaubry/YamlDotNet/blob/f18356c28bd11465f9ba1f8451dfbd6ec3ffe919/YamlDotNet/Core/Scanner.cs#L420

EdwardCooke avatar Feb 10 '23 15:02 EdwardCooke

It’s actually valid yaml. A key can be empty or null.

EdwardCooke avatar Feb 10 '23 15:02 EdwardCooke

I also have this issue

rgbav avatar Mar 08 '23 15:03 rgbav

Is this still an issue in the latest version?

EdwardCooke avatar Sep 01 '23 19:09 EdwardCooke

In the deserializer there's nothing we can do since the .NET dictionary class doesn't allow null keys. However, it looks like the scanner isn't reading it correctly so the yamlstream doesn't pick it up. It sees the empty scalar, but after the colon it doesn't pick up the next scalar. I'm still researching it and will try and get a fix in before I put out the next release.

EdwardCooke avatar Sep 02 '23 16:09 EdwardCooke