mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-07 05:59:06 +02:00
[client] Use punycode domains internally consequently (#3867)
This commit is contained in:
@@ -30,7 +30,7 @@ func (d Domain) SafeString() string {
|
||||
}
|
||||
|
||||
// PunycodeString returns the punycode representation of the Domain.
|
||||
// This should only be used if a punycode domain is expected but only a string is supported.
|
||||
// This should only be used if a punycode domain is expected but only a string is supported (e.g. an external library).
|
||||
func (d Domain) PunycodeString() string {
|
||||
return string(d)
|
||||
}
|
||||
|
||||
+11
-15
@@ -1,7 +1,7 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -41,6 +41,7 @@ func (d List) ToSafeStringList() []string {
|
||||
}
|
||||
|
||||
// String converts List to a comma-separated string.
|
||||
// This is useful for displaying domain names in a user-friendly format.
|
||||
func (d List) String() (string, error) {
|
||||
list, err := d.ToStringList()
|
||||
if err != nil {
|
||||
@@ -50,7 +51,8 @@ func (d List) String() (string, error) {
|
||||
}
|
||||
|
||||
// SafeString converts List to a comma-separated non-punycode string.
|
||||
// If a domain cannot be converted, the original string is used.
|
||||
// This is useful for displaying domain names in a user-friendly format.
|
||||
// If a domain cannot be converted, the original (punycode) string is used.
|
||||
func (d List) SafeString() string {
|
||||
str, err := d.String()
|
||||
if err != nil {
|
||||
@@ -64,28 +66,22 @@ func (d List) PunycodeString() string {
|
||||
return strings.Join(d.ToPunycodeList(), ", ")
|
||||
}
|
||||
|
||||
// Equal checks if two domain lists are equal without considering the order.
|
||||
func (d List) Equal(domains List) bool {
|
||||
if len(d) != len(domains) {
|
||||
return false
|
||||
}
|
||||
|
||||
sort.Slice(d, func(i, j int) bool {
|
||||
return d[i] < d[j]
|
||||
})
|
||||
d1 := slices.Clone(d)
|
||||
d2 := slices.Clone(domains)
|
||||
|
||||
sort.Slice(domains, func(i, j int) bool {
|
||||
return domains[i] < domains[j]
|
||||
})
|
||||
slices.Sort(d1)
|
||||
slices.Sort(d2)
|
||||
|
||||
for i, domain := range d {
|
||||
if domain != domains[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return slices.Equal(d1, d2)
|
||||
}
|
||||
|
||||
// FromStringList creates a DomainList from a slice of string.
|
||||
// FromStringList creates a List from a slice of strings.
|
||||
func FromStringList(s []string) (List, error) {
|
||||
var dl List
|
||||
for _, domain := range s {
|
||||
|
||||
Reference in New Issue
Block a user