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

Allow to parse uppercase 0X #842

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions neo.UnitTests/UT_UIntBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public void TestSetup()
}
}

[TestMethod]
public void Test_UInt160_Parse()
{
string uint160strbig = "0x0001020304050607080900010203040506070809";
UInt160 num1 = UInt160.Parse(uint160strbig);
num1.ToString().Should().Be("0x0001020304050607080900010203040506070809");

string uint160strbig2 = "0X0001020304050607080900010203040506070809";
UInt160 num2 = UInt160.Parse(uint160strbig2);
num2.ToString().Should().Be("0x0001020304050607080900010203040506070809");
}

private byte[] RandomBytes(int count)
{
byte[] randomBytes = new byte[count];
Expand Down
4 changes: 2 additions & 2 deletions neo/UInt160.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public unsafe bool Equals(UInt160 other)
{
if (value == null)
throw new ArgumentNullException();
if (value.StartsWith("0x"))
if (value.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
value = value.Substring(2);
if (value.Length != 40)
throw new FormatException();
Expand All @@ -95,7 +95,7 @@ public static bool TryParse(string s, out UInt160 result)
result = null;
return false;
}
if (s.StartsWith("0x"))
if (s.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
s = s.Substring(2);
if (s.Length != 40)
{
Expand Down
4 changes: 2 additions & 2 deletions neo/UInt256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public unsafe bool Equals(UInt256 other)
{
if (s == null)
throw new ArgumentNullException();
if (s.StartsWith("0x"))
if (s.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
s = s.Substring(2);
if (s.Length != 64)
throw new FormatException();
Expand All @@ -96,7 +96,7 @@ public static bool TryParse(string s, out UInt256 result)
result = null;
return false;
}
if (s.StartsWith("0x"))
if (s.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
s = s.Substring(2);
if (s.Length != 64)
{
Expand Down