Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Json.Serialize map keys #1705

Merged
merged 3 commits into from
Jun 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/neo/SmartContract/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static JObject Serialize(StackItem item)

foreach (var entry in map)
{
if (!(entry.Key is ByteString)) throw new FormatException();

var key = entry.Key.GetString();
var value = Serialize(entry.Value);

Expand Down Expand Up @@ -106,6 +108,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize)
stack.Push(JsonTokenType.EndObject);
foreach (var pair in map.Reverse())
{
if (!(pair.Key is ByteString)) throw new FormatException();
stack.Push(pair.Value);
stack.Push(pair.Key);
stack.Push(JsonTokenType.PropertyName);
Expand All @@ -115,7 +118,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize)
writer.WriteEndObject();
break;
case JsonTokenType.PropertyName:
writer.WritePropertyName(((PrimitiveType)stack.Pop()).GetSpan());
writer.WritePropertyName(((ByteString)stack.Pop()).GetSpan());
break;
case Null _:
writer.WriteNullValue();
Expand Down