diff --git a/src/Neo/UInt160.cs b/src/Neo/UInt160.cs index 6aa4a9eaa9..0882687b9f 100644 --- a/src/Neo/UInt160.cs +++ b/src/Neo/UInt160.cs @@ -161,7 +161,7 @@ public static bool TryParse(string str, out UInt160 result) var data = new byte[Length]; for (var i = 0; i < Length; i++) { - if (!byte.TryParse(str.AsSpan(i * 2 + startIndex, 2), NumberStyles.HexNumber, null, out data[Length - i - 1])) + if (!byte.TryParse(str.AsSpan(i * 2 + startIndex, 2), NumberStyles.AllowHexSpecifier, null, out data[Length - i - 1])) return false; } result = new(data); diff --git a/tests/Neo.UnitTests/UT_UInt160.cs b/tests/Neo.UnitTests/UT_UInt160.cs index 3fb9dd89a0..3c3b1ec001 100644 --- a/tests/Neo.UnitTests/UT_UInt160.cs +++ b/tests/Neo.UnitTests/UT_UInt160.cs @@ -98,6 +98,7 @@ public void TestTryParse() Assert.AreEqual("0x1230000000000000000000000000000000000000", temp.ToString()); Assert.AreEqual(false, UInt160.TryParse("000000000000000000000000000000000000000", out _)); Assert.AreEqual(false, UInt160.TryParse("0xKK00000000000000000000000000000000000000", out _)); + Assert.AreEqual(false, UInt160.TryParse(" 1 2 3 45 000000000000000000000000000000", out _)); } [TestMethod]