nns: allow hyphen in domain names

Port https://github.com/nspcc-dev/neofs-contract/pull/183.
This commit is contained in:
Anna Shaleva 2022-09-05 17:30:43 +03:00
parent bd3722041a
commit c11481b119
2 changed files with 11 additions and 3 deletions

View file

@ -507,6 +507,8 @@ func checkCommittee() {
}
// checkFragment validates root or a part of domain name.
// 1. Root domain must start with a letter.
// 2. All other fragments must start and end in a letter or a digit.
func checkFragment(v string, isRoot bool) bool {
maxLength := maxDomainNameFragmentLength
if isRoot {
@ -525,12 +527,12 @@ func checkFragment(v string, isRoot bool) bool {
return false
}
}
for i := 1; i < len(v); i++ {
if !isAlNum(v[i]) {
for i := 1; i < len(v)-1; i++ {
if v[i] != '-' && !isAlNum(v[i]) {
return false
}
}
return true
return isAlNum(v[len(v)-1])
}
// isAlNum checks whether provided char is a lowercase letter or a number.

View file

@ -173,6 +173,12 @@ func TestRegisterAndRenew(t *testing.T) {
c.Invoke(t, false, "register", "neo.com", e.CommitteeHash)
c.Invoke(t, false, "isAvailable", "neo.com")
t.Run("domain names with hyphen", func(t *testing.T) {
c.InvokeFail(t, "invalid domain name format", "register", "-testdomain.com", e.CommitteeHash)
c.InvokeFail(t, "invalid domain name format", "register", "testdomain-.com", e.CommitteeHash)
c.Invoke(t, true, "register", "test-domain.com", e.CommitteeHash)
})
props := stackitem.NewMap()
props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))