Add null tests
MODIFY
WalletWasabi.Tests/ParserTests.cs
WalletWasabi.Tests/ParserTests.cs
@@ -163,6 +163,9 @@ namespace WalletWasabi.Tests
Assert.False(AddressStringParser.TryParseBitcoinAddress(test.address.Remove(5, 1), test.network, out _));
Assert.False(AddressStringParser.TryParseBitcoinAddress(test.address.Insert(1, "b"), test.network, out _));
+ AddressStringParser.TryParseBitcoinAddress(test.address, null, out _);
+ AddressStringParser.TryParseBitcoinAddress(null, test.network, out _);
+
Assert.True(AddressStringParser.TryParseBitcoinAddress(test.address, test.network, out BitcoinUrlBuilder result));
Assert.Equal(test.address, result.Address.ToString());
@@ -191,6 +194,9 @@ namespace WalletWasabi.Tests
Assert.False(AddressStringParser.TryParseBitcoinUrl(test.url.Remove(5, 4), test.network, out _));
Assert.False(AddressStringParser.TryParseBitcoinUrl(test.url.Insert(1, "b"), test.network, out _));
+ AddressStringParser.TryParseBitcoinUrl(test.url, null, out _);
+ AddressStringParser.TryParseBitcoinUrl(null, test.network, out _);
+
Assert.True(AddressStringParser.TryParseBitcoinUrl(test.url, test.network, out BitcoinUrlBuilder result));
Assert.Equal(test.url.Split(new[] { ':', '?' })[1], result.Address.ToString());

MODIFY
WalletWasabi/Helpers/AddressStringParser.cs
WalletWasabi/Helpers/AddressStringParser.cs
@@ -12,13 +12,18 @@ namespace WalletWasabi.Helpers
{
url = null;
- if (text is null || text.Length > 100 || text.Length < 20 || expectedNetwork is null)
+ if (text is null || expectedNetwork is null)
{
return false;
}
text = text.Trim();
+ if (text.Length > 100 || text.Length < 20)
+ {
+ return false;
+ }
+
try
{
var bitcoinAddress = BitcoinAddress.Create(text, expectedNetwork);
@@ -35,13 +40,18 @@ namespace WalletWasabi.Helpers
{
url = null;
- if (text is null || text.Length > 1000 || text.Length < 20 || expectedNetwork is null)
+ if (text is null || expectedNetwork is null)
{
return false;
}
text = text.Trim();
+ if (text.Length > 1000 || text.Length < 20)
+ {
+ return false;
+ }
+
try
{
var bitcoinUrl = new BitcoinUrlBuilder(text);

Add null tests