Cleanup model/utils.go (#17945)
* Cleanup model/utils.go - Removed some functions which were unsued. (The unused linter was somehow failing to catch this). - Moved some functions inside other packages. - Removed two duplicate instances of the same function - RemoveDuplicateStrings and UniqueStrings. - Moved some regexes to global vars to prevent compilation every time. ```release-note NONE ``` * fix lint ```release-note NONE ``` * bring back unused exception ```release-note NONE ``` * fix tests ```release-note NONE ``` * Address review comments ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
77f9620997
Коммит
7454680be5
@@ -1768,7 +1768,7 @@ type SupportSettings struct {
|
||||
}
|
||||
|
||||
func (s *SupportSettings) SetDefaults() {
|
||||
if !IsSafeLink(s.TermsOfServiceLink) {
|
||||
if !isSafeLink(s.TermsOfServiceLink) {
|
||||
*s.TermsOfServiceLink = SupportSettingsDefaultTermsOfServiceLink
|
||||
}
|
||||
|
||||
@@ -1776,7 +1776,7 @@ func (s *SupportSettings) SetDefaults() {
|
||||
s.TermsOfServiceLink = NewString(SupportSettingsDefaultTermsOfServiceLink)
|
||||
}
|
||||
|
||||
if !IsSafeLink(s.PrivacyPolicyLink) {
|
||||
if !isSafeLink(s.PrivacyPolicyLink) {
|
||||
*s.PrivacyPolicyLink = ""
|
||||
}
|
||||
|
||||
@@ -1784,7 +1784,7 @@ func (s *SupportSettings) SetDefaults() {
|
||||
s.PrivacyPolicyLink = NewString(SupportSettingsDefaultPrivacyPolicyLink)
|
||||
}
|
||||
|
||||
if !IsSafeLink(s.AboutLink) {
|
||||
if !isSafeLink(s.AboutLink) {
|
||||
*s.AboutLink = ""
|
||||
}
|
||||
|
||||
@@ -1792,7 +1792,7 @@ func (s *SupportSettings) SetDefaults() {
|
||||
s.AboutLink = NewString(SupportSettingsDefaultAboutLink)
|
||||
}
|
||||
|
||||
if !IsSafeLink(s.HelpLink) {
|
||||
if !isSafeLink(s.HelpLink) {
|
||||
*s.HelpLink = ""
|
||||
}
|
||||
|
||||
@@ -1800,7 +1800,7 @@ func (s *SupportSettings) SetDefaults() {
|
||||
s.HelpLink = NewString(SupportSettingsDefaultHelpLink)
|
||||
}
|
||||
|
||||
if !IsSafeLink(s.ReportAProblemLink) {
|
||||
if !isSafeLink(s.ReportAProblemLink) {
|
||||
*s.ReportAProblemLink = ""
|
||||
}
|
||||
|
||||
@@ -3669,7 +3669,7 @@ func (s *ServiceSettings) isValid() *AppError {
|
||||
if host == "" {
|
||||
isValidHost = true
|
||||
} else {
|
||||
isValidHost = (net.ParseIP(host) != nil) || IsDomainName(host)
|
||||
isValidHost = (net.ParseIP(host) != nil) || isDomainName(host)
|
||||
}
|
||||
portInt, err := strconv.Atoi(port)
|
||||
if err != nil || !isValidHost || portInt < 0 || portInt > math.MaxUint16 {
|
||||
@@ -3974,3 +3974,71 @@ func isTagPresent(tag string, tags []string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Copied from https://golang.org/src/net/dnsclient.go#L119
|
||||
func isDomainName(s string) bool {
|
||||
// See RFC 1035, RFC 3696.
|
||||
// Presentation format has dots before every label except the first, and the
|
||||
// terminal empty label is optional here because we assume fully-qualified
|
||||
// (absolute) input. We must therefore reserve space for the first and last
|
||||
// labels' length octets in wire format, where they are necessary and the
|
||||
// maximum total length is 255.
|
||||
// So our _effective_ maximum is 253, but 254 is not rejected if the last
|
||||
// character is a dot.
|
||||
l := len(s)
|
||||
if l == 0 || l > 254 || l == 254 && s[l-1] != '.' {
|
||||
return false
|
||||
}
|
||||
|
||||
last := byte('.')
|
||||
ok := false // Ok once we've seen a letter.
|
||||
partlen := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
switch {
|
||||
default:
|
||||
return false
|
||||
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
|
||||
ok = true
|
||||
partlen++
|
||||
case '0' <= c && c <= '9':
|
||||
// fine
|
||||
partlen++
|
||||
case c == '-':
|
||||
// Byte before dash cannot be dot.
|
||||
if last == '.' {
|
||||
return false
|
||||
}
|
||||
partlen++
|
||||
case c == '.':
|
||||
// Byte before dot cannot be dot, dash.
|
||||
if last == '.' || last == '-' {
|
||||
return false
|
||||
}
|
||||
if partlen > 63 || partlen == 0 {
|
||||
return false
|
||||
}
|
||||
partlen = 0
|
||||
}
|
||||
last = c
|
||||
}
|
||||
if last == '-' || partlen > 63 {
|
||||
return false
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
func isSafeLink(link *string) bool {
|
||||
if link != nil {
|
||||
if IsValidHttpUrl(*link) {
|
||||
return true
|
||||
} else if strings.HasPrefix(*link, "/") {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user