Skip to content

Commit

Permalink
feat: support hostname target (#1455)
Browse files Browse the repository at this point in the history
Signed-off-by: ldysdu <ldysdu@163.com>
  • Loading branch information
ldysdu authored Jan 3, 2024
1 parent ea282d1 commit 4bb4ab6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@Constraint(validatedBy = HostParamValidator.class)
public @interface HostValid {

String message() default "Host need ipv4,ipv6 or domain,<br>EG:127.0.0.1 hertzbeat.com";
String message() default "Host need ipv4,ipv6,hostname or domain,<br>EG:127.0.0.1 hertzbeat.com";

Class<?>[] groups() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class IpDomainUtil {

private static final Pattern DOMAIN_PATTERN =
Pattern.compile("^(?=^.{3,255}$)[_a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+$");
Pattern.compile("^[-\\w]+(\\.[-\\w]+)*$");

private static final String LOCALHOST = "localhost";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ void validateIpDomain() {
assertTrue(IpDomainUtil.validateIpDomain("good.didi"));
assertTrue(IpDomainUtil.validateIpDomain("spider_rds.sogou"));
assertTrue(IpDomainUtil.validateIpDomain("_redis.hn.sogou"));
assertFalse(IpDomainUtil.validateIpDomain("tmp"));
assertFalse(IpDomainUtil.validateIpDomain("good"));
assertTrue(IpDomainUtil.validateIpDomain("host"));
assertTrue(IpDomainUtil.validateIpDomain("host-1"));
assertFalse(IpDomainUtil.validateIpDomain("www.baidu.com."));
assertFalse(IpDomainUtil.validateIpDomain("good."));
assertFalse(IpDomainUtil.validateIpDomain(".good."));
assertFalse(IpDomainUtil.validateIpDomain("www.baidu..com"));
assertFalse(IpDomainUtil.validateIpDomain("www.baidu*com"));
assertFalse(IpDomainUtil.validateIpDomain("host$-1"));
}

@Test
Expand All @@ -54,4 +57,4 @@ void isHasSchema() {
assertFalse(IpDomainUtil.isHasSchema("www.baidu.com"));
assertFalse(IpDomainUtil.isHasSchema("https_www.baidu.com"));
}
}
}

0 comments on commit 4bb4ab6

Please sign in to comment.