Merge pull request #3964 from wiz/fix-devin-btcnode-regex

Fix btcnode validation regex to handle multiple FQDNs, add tests
This commit is contained in:
Christoph Atteneder 2020-02-11 13:41:24 +01:00 committed by GitHub
commit 64e4438702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1135,7 +1135,7 @@ public class GUIUtil {
"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" + // 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33
")"; // (IPv4-Embedded IPv6 Address)
ipv6RegexPattern = String.format("(?:%1$s)|(?:\\[%1$s\\]\\:%2$s)", ipv6RegexPattern, portRegexPattern);
String fqdnRegexPattern = String.format("(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\\.)+(?!onion)[a-zA-Z]{2,63}(?:\\:%1$s)?$)", 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))*$",
onionV2RegexPattern, ipv4RegexPattern, ipv6RegexPattern, fqdnRegexPattern));
return regexValidator;

View File

@ -165,6 +165,12 @@ public class GUIUtilTest {
// fqdn addresses
assertTrue(regexValidator.validate("example.com").isValid);
assertTrue(regexValidator.validate("mynode.local:8333").isValid);
assertTrue(regexValidator.validate("foo.example.com,bar.example.com").isValid);
assertTrue(regexValidator.validate("foo.example.com:8333,bar.example.com:8333").isValid);
assertFalse(regexValidator.validate("mynode.local:65536").isValid);
assertFalse(regexValidator.validate("-example.com").isValid);
assertFalse(regexValidator.validate("example-.com").isValid);
}
@Test