Skip to content

Commit

Permalink
Merge pull request #3964 from wiz/fix-devin-btcnode-regex
Browse files Browse the repository at this point in the history
Fix btcnode validation regex to handle multiple FQDNs, add tests
  • Loading branch information
ripcurlx authored Feb 11, 2020
2 parents 777052f + 7f92d12 commit 64e4438
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion desktop/src/main/java/bisq/desktop/util/GUIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ public static RegexValidator addressRegexValidator() {
"(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;
Expand Down
6 changes: 6 additions & 0 deletions desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ public void testAddressRegexValidator() {
// 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
Expand Down

0 comments on commit 64e4438

Please sign in to comment.