Skip to content

Commit

Permalink
Bypass "docs" in anchor idl generation
Browse files Browse the repository at this point in the history
Issue:
From issue bmresearch#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.
  • Loading branch information
EnderElement authored May 4, 2023
1 parent ffa353a commit fad5b22
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Solnet.Anchor/Converters/IIdlTypeDefinitionTyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -173,4 +196,4 @@ public override void Write(Utf8JsonWriter writer, IIdlTypeDefinitionTy[] value,
throw new NotImplementedException();
}
}
}
}

0 comments on commit fad5b22

Please sign in to comment.