mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Merge pull request #4346 from jmacxx/fix_regex_tor3
Fix tor v3 address validation
This commit is contained in:
commit
149cf1381a
2 changed files with 5 additions and 3 deletions
|
@ -1129,6 +1129,7 @@ public class GUIUtil {
|
||||||
RegexValidator regexValidator = new RegexValidator();
|
RegexValidator regexValidator = new RegexValidator();
|
||||||
String portRegexPattern = "(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])";
|
String portRegexPattern = "(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])";
|
||||||
String onionV2RegexPattern = String.format("[a-zA-Z2-7]{16}\\.onion(?:\\:%1$s)?", portRegexPattern);
|
String onionV2RegexPattern = String.format("[a-zA-Z2-7]{16}\\.onion(?:\\:%1$s)?", portRegexPattern);
|
||||||
|
String onionV3RegexPattern = String.format("[a-zA-Z2-7]{56}\\.onion(?:\\:%1$s)?", portRegexPattern);
|
||||||
String ipv4RegexPattern = String.format("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
|
String ipv4RegexPattern = String.format("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
|
||||||
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" +
|
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" +
|
||||||
"(?:\\:%1$s)?", portRegexPattern);
|
"(?:\\:%1$s)?", portRegexPattern);
|
||||||
|
@ -1152,8 +1153,8 @@ public class GUIUtil {
|
||||||
")"; // (IPv4-Embedded IPv6 Address)
|
")"; // (IPv4-Embedded IPv6 Address)
|
||||||
ipv6RegexPattern = String.format("(?:%1$s)|(?:\\[%1$s\\]\\:%2$s)", ipv6RegexPattern, portRegexPattern);
|
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);
|
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)),\\s*)*(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s))*$",
|
regexValidator.setPattern(String.format("^(?:(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s)|(?:%5$s)),\\s*)*(?:(?:%1$s)|(?:%2$s)|(?:%3$s)|(?:%4$s)|(?:%5$s))*$",
|
||||||
onionV2RegexPattern, ipv4RegexPattern, ipv6RegexPattern, fqdnRegexPattern));
|
onionV2RegexPattern, onionV3RegexPattern, ipv4RegexPattern, ipv6RegexPattern, fqdnRegexPattern));
|
||||||
return regexValidator;
|
return regexValidator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,8 @@ public class GUIUtilTest {
|
||||||
assertFalse(regexValidator.validate("abcdefghijklmnop.onion:").isValid);
|
assertFalse(regexValidator.validate("abcdefghijklmnop.onion:").isValid);
|
||||||
|
|
||||||
// onion v3 addresses
|
// onion v3 addresses
|
||||||
assertFalse(regexValidator.validate("32zzibxmqi2ybxpqyggwwuwz7a3lbvtzoloti7cxoevyvijexvgsfeid.onion:8333").isValid);
|
assertFalse(regexValidator.validate("32zzibxmqi2ybxpqyggwwuwz7a3lbvtzoloti7cxoevyvijexvgsfei.onion:8333").isValid); // 1 missing char
|
||||||
|
assertTrue(regexValidator.validate("wizseedscybbttk4bmb2lzvbuk2jtect37lcpva4l3twktmkzemwbead.onion:8000").isValid);
|
||||||
|
|
||||||
// ipv4 addresses
|
// ipv4 addresses
|
||||||
assertTrue(regexValidator.validate("12.34.56.78").isValid);
|
assertTrue(regexValidator.validate("12.34.56.78").isValid);
|
||||||
|
|
Loading…
Add table
Reference in a new issue