2022-04-22 17:38:40 +02:00
|
|
|
package clean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Uri removes invalid character from an uri string.
|
|
|
|
func Uri(s string) string {
|
2024-01-15 13:06:27 +01:00
|
|
|
if s == "" || len(s) > MaxLength {
|
|
|
|
return ""
|
|
|
|
} else if strings.Contains(s, "..") {
|
2022-04-22 17:38:40 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trim whitespace.
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
|
|
|
|
if uri, err := url.Parse(s); err != nil {
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
return uri.String()
|
|
|
|
}
|
|
|
|
}
|