fix: domain name validation

hopefully
This commit is contained in:
Yiyang Kang 2022-11-23 05:09:54 +08:00
parent 440d36b291
commit 2e6cd26cec
1 changed files with 4 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import (
"time"
"github.com/go-errors/errors"
"golang.org/x/net/idna"
"git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/utils"
)
@ -27,7 +28,7 @@ var (
digErrInvalidArgs = fmt.Errorf("invalid request")
digDnsNameRe = regexp.MustCompile(`^([a-z0-9_-]+\.?)+|\.$`)
digIdnaMapper = idna.New(idna.MapForLookup(), idna.StrictDomainName(false))
)
type DigRequest struct {
@ -61,8 +62,8 @@ func NewDigRequest(req string) (*DigRequest, error) {
return ret, nil
}
name := strings.ToLower(args[0])
if !digDnsNameRe.Match([]byte(name)) {
name, err := digIdnaMapper.ToASCII(args[0])
if err != nil {
return nil, digErrInvalidArgs
}
ret.Name = name