From fad5b226daa8f82ae8b8143bc63707f259c05fde Mon Sep 17 00:00:00 2001 From: EnderElement <1000n00bshater@gmail.com> Date: Thu, 4 May 2023 22:01:17 +1000 Subject: [PATCH] Bypass "docs" in anchor idl generation Issue: From issue #22, generating code from an anchor idl which contains a docs element such as "docs":[ "String" ] will crash the code when executed. Solution: These lines of code will be able to look at the docs section without issue, however these changes do not generate code with the contents of docs. --- .../IIdlTypeDefinitionTyConverter.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Solnet.Anchor/Converters/IIdlTypeDefinitionTyConverter.cs b/Solnet.Anchor/Converters/IIdlTypeDefinitionTyConverter.cs index 16a4c00..d183310 100644 --- a/Solnet.Anchor/Converters/IIdlTypeDefinitionTyConverter.cs +++ b/Solnet.Anchor/Converters/IIdlTypeDefinitionTyConverter.cs @@ -33,7 +33,30 @@ public override IIdlTypeDefinitionTy[] Read(ref Utf8JsonReader reader, Type type if (reader.TokenType != JsonTokenType.String) throw new JsonException("Unexpected error value."); string typeName = reader.GetString(); + + reader.Read(); + if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); + + propertyName = reader.GetString(); + if ("docs" != propertyName) throw new JsonException("Unexpected error value."); + + reader.Read(); + if (reader.TokenType != JsonTokenType.StartArray) throw new JsonException("Unexpected error value."); + + reader.Read(); + if (reader.TokenType != JsonTokenType.String) throw new JsonException("Unexpected error value."); + + again: + reader.Read(); + if (reader.TokenType == JsonTokenType.String) + { + if (reader.TokenType != JsonTokenType.String) throw new JsonException("Unexpected error value."); + goto again; + } + + if (reader.TokenType != JsonTokenType.EndArray) throw new JsonException("Unexpected error value."); + reader.Read(); if (reader.TokenType != JsonTokenType.PropertyName) throw new JsonException("Unexpected error value."); @@ -173,4 +196,4 @@ public override void Write(Utf8JsonWriter writer, IIdlTypeDefinitionTy[] value, throw new NotImplementedException(); } } -} \ No newline at end of file +}