nns: allow hyphen in domain names
Port https://github.com/nspcc-dev/neofs-contract/pull/183.
This commit is contained in:
parent
bd3722041a
commit
c11481b119
2 changed files with 11 additions and 3 deletions
|
@ -507,6 +507,8 @@ func checkCommittee() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkFragment validates root or a part of domain name.
|
// 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 {
|
func checkFragment(v string, isRoot bool) bool {
|
||||||
maxLength := maxDomainNameFragmentLength
|
maxLength := maxDomainNameFragmentLength
|
||||||
if isRoot {
|
if isRoot {
|
||||||
|
@ -525,12 +527,12 @@ func checkFragment(v string, isRoot bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := 1; i < len(v); i++ {
|
for i := 1; i < len(v)-1; i++ {
|
||||||
if !isAlNum(v[i]) {
|
if v[i] != '-' && !isAlNum(v[i]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return isAlNum(v[len(v)-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// isAlNum checks whether provided char is a lowercase letter or a number.
|
// isAlNum checks whether provided char is a lowercase letter or a number.
|
||||||
|
|
|
@ -173,6 +173,12 @@ func TestRegisterAndRenew(t *testing.T) {
|
||||||
c.Invoke(t, false, "register", "neo.com", e.CommitteeHash)
|
c.Invoke(t, false, "register", "neo.com", e.CommitteeHash)
|
||||||
c.Invoke(t, false, "isAvailable", "neo.com")
|
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 := stackitem.NewMap()
|
||||||
props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
|
props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
|
||||||
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
|
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
|
||||||
|
|
Loading…
Reference in a new issue