add seperate PunifyValidate() function for properly validating domain names when converting to punycode

This commit is contained in:
kim 2025-01-13 15:20:38 +00:00
commit 6c9a3e4a56
9 changed files with 198 additions and 185 deletions

View file

@ -158,9 +158,10 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i
}
func (i *instanceDB) GetInstance(ctx context.Context, domain string) (*gtsmodel.Instance, error) {
// Normalize the domain as punycode
var err error
domain, err = util.Punify(domain)
// Normalize the domain as punycode
domain, err = util.Punify_(domain)
if err != nil {
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
}
@ -265,8 +266,9 @@ func (i *instanceDB) PopulateInstance(ctx context.Context, instance *gtsmodel.In
func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instance) error {
var err error
// Normalize the domain as punycode
instance.Domain, err = util.Punify(instance.Domain)
// Normalize the domain as punycode, note the extra
// validation step for domain name write operations.
instance.Domain, err = util.PunifyValidate(instance.Domain)
if err != nil {
return gtserror.Newf("error punifying domain %s: %w", instance.Domain, err)
}
@ -279,9 +281,11 @@ func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instanc
}
func (i *instanceDB) UpdateInstance(ctx context.Context, instance *gtsmodel.Instance, columns ...string) error {
// Normalize the domain as punycode
var err error
instance.Domain, err = util.Punify(instance.Domain)
// Normalize the domain as punycode, note the extra
// validation step for domain name write operations.
instance.Domain, err = util.PunifyValidate(instance.Domain)
if err != nil {
return gtserror.Newf("error punifying domain %s: %w", instance.Domain, err)
}
@ -349,9 +353,10 @@ func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, max
limit = 0
}
// Normalize the domain as punycode.
var err error
domain, err = util.Punify(domain)
// Normalize the domain as punycode
domain, err = util.Punify_(domain)
if err != nil {
return nil, gtserror.Newf("error punifying domain %s: %w", domain, err)
}