parent
440d36b291
commit
2e6cd26cec
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue