Fix address validation for whitespace after comma

Typical comma separated values have a space after each comma
in order to make the list more human-readable.  In some areas
of bisq, comma separated lists are generated this way (see #4203),
but the validation of comma separated addresses was not accepting
spaces after commas.  This change to the regex allows optional
whitespace after comma separators.  A new test has been
added to validate the scenario of whitespace after comma.

Fixes #4203
This commit is contained in:
jmacxx 2020-05-10 16:40:36 -05:00
parent 246d5ee37a
commit f4064dfcfb
No known key found for this signature in database
GPG key ID: 155297BABFE94A1B
2 changed files with 2 additions and 1 deletions

View file

@ -1152,7 +1152,7 @@ public class GUIUtil {
")"; // (IPv4-Embedded IPv6 Address)
ipv6RegexPattern = String.format("(?:%1$s)|(?:\\[%1$s\\]\\:%2$s)", ipv6RegexPattern, portRegexPattern);
String fqdnRegexPattern = String.format("(((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\\.)+(?!onion)[a-zA-Z]{2,63}(?:\\:%1$s)?)", portRegexPattern);
regexValidator.setPattern(String.format("^(?:(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s)),)*(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s))*$",
regexValidator.setPattern(String.format("^(?:(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s)),\\s*)*(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s))*$",
onionV2RegexPattern, ipv4RegexPattern, ipv6RegexPattern, fqdnRegexPattern));
return regexValidator;
}

View file

@ -129,6 +129,7 @@ public class GUIUtilTest {
// onion V2 addresses
assertTrue(regexValidator.validate("abcdefghij234567.onion").isValid);
assertTrue(regexValidator.validate("abcdefghijklmnop.onion,abcdefghijklmnop.onion").isValid);
assertTrue(regexValidator.validate("abcdefghijklmnop.onion, abcdefghijklmnop.onion").isValid);
assertTrue(regexValidator.validate("qrstuvwxyzABCDEF.onion,qrstuvwxyzABCDEF.onion,aaaaaaaaaaaaaaaa.onion").isValid);
assertTrue(regexValidator.validate("GHIJKLMNOPQRSTUV.onion:9999").isValid);
assertTrue(regexValidator.validate("WXYZ234567abcdef.onion,GHIJKLMNOPQRSTUV.onion:9999").isValid);