c5f6a28448
In addition, the Access-Control-Allow-Origin header is set to the same URL if an Origin header is found in the request (experimental). Signed-off-by: Michael Mayer <michael@photoprism.app>
24 lines
373 B
Go
24 lines
373 B
Go
package clean
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
// Uri removes invalid character from an uri string.
|
|
func Uri(s string) string {
|
|
if s == "" || len(s) > MaxLength {
|
|
return ""
|
|
} else if strings.Contains(s, "..") {
|
|
return ""
|
|
}
|
|
|
|
// Trim whitespace.
|
|
s = strings.TrimSpace(s)
|
|
|
|
if uri, err := url.Parse(s); err != nil {
|
|
return ""
|
|
} else {
|
|
return uri.String()
|
|
}
|
|
}
|