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

Fix #1714 #1715

Merged
merged 5 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/neo/SmartContract/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static StackItem Deserialize(JObject json, ReferenceCounter referenceCoun
}
case JString str:
{
return str.Value;
return Convert.FromBase64String(str.Value);
}
case JNumber num:
{
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/SmartContract/UT_JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void Serialize_Array_Bool_Str_Num()
[TestMethod]
public void Deserialize_Array_Bool_Str_Num()
{
var items = JsonSerializer.Deserialize(JObject.Parse("[true,\"test\",123]"));
var items = JsonSerializer.Deserialize(JObject.Parse("[true,\"dGVzdA==\",123]"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that also it should work with strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how do you distinguish between base64 strings and ordinary strings that only use the base64 character set?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how do you distinguish between base64 strings and ordinary strings that only use the base64 character set?

Now we can't. But in json it's more common to find a string than a binary content. If we should decide by one, i prefer string.

Other idea, I think that we should change the deserialization way, and create a object inside the VM. With the type and the value, we had a lot of troubles with json because of this. It's better to deserialize it in Array(type,value), we will be able to deserialize it exactly like it was received.


Assert.IsInstanceOfType(items, typeof(VM.Types.Array));
Assert.AreEqual(((VM.Types.Array)items).Count, 3);
Expand Down Expand Up @@ -312,7 +312,7 @@ public void Serialize_Array_OfArray()
[TestMethod]
public void Deserialize_Array_OfArray()
{
var items = JsonSerializer.Deserialize(JObject.Parse("[[true,\"test1\",123],[true,\"test2\",321]]"));
var items = JsonSerializer.Deserialize(JObject.Parse("[[true,\"dGVzdDE=\",123],[true,\"dGVzdDI=\",321]]"));

Assert.IsInstanceOfType(items, typeof(VM.Types.Array));
Assert.AreEqual(((VM.Types.Array)items).Count, 2);
Expand Down