diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-06-10 02:44:47 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-06-10 02:44:47 +0200 |
commit | 3df825260d577ac6e3c4871a6c198af06755300b (patch) | |
tree | 4798a9d496ff93feacc36f9f640e4039765fa374 | |
parent | 4044d9753da11e7e66234621f52b3dcd04f73b41 (diff) | |
download | refcat-3df825260d577ac6e3c4871a6c198af06755300b.tar.gz refcat-3df825260d577ac6e3c4871a6c198af06755300b.zip |
make prefix helper public
-rw-r--r-- | skate/cmd/skate-cleanup/main.go | 11 | ||||
-rw-r--r-- | skate/url.go | 6 |
2 files changed, 4 insertions, 13 deletions
diff --git a/skate/cmd/skate-cleanup/main.go b/skate/cmd/skate-cleanup/main.go index 72b258a..d4d5f5a 100644 --- a/skate/cmd/skate-cleanup/main.go +++ b/skate/cmd/skate-cleanup/main.go @@ -59,15 +59,6 @@ func main() { } } -func hasAnyPrefix(s string, prefixes []string) bool { - for _, p := range prefixes { - if strings.HasPrefix(s, p) { - return true - } - } - return false -} - // urlFilter parses finds the first URL. func urlFilter(p []byte) ([]byte, error) { parts := strings.Split(string(p), *delimiter) @@ -87,7 +78,7 @@ func urlFilter(p []byte) ([]byte, error) { if url == "" && *skipNonMatches { return nil, nil } - if len(allowedSchemas) > 0 && !hasAnyPrefix(url, allowedSchemas) { + if len(allowedSchemas) > 0 && !skate.HasAnyPrefix(url, allowedSchemas) { return nil, nil } if len(parts) == 1 || *index == len(parts) { diff --git a/skate/url.go b/skate/url.go index 4ea406e..f619b24 100644 --- a/skate/url.go +++ b/skate/url.go @@ -28,7 +28,7 @@ var ( // really work, as syntactically valid URL strings may still be improbable // URLs, e.g. http://!!!x.com, etc. func SanitizeURL(s string) string { - if !hasAnyPrefix(s, okPrefixes) { + if !HasAnyPrefix(s, okPrefixes) { s = sanitizeRaw(s) if s == "" { return s @@ -82,8 +82,8 @@ func sanitizeRaw(s string) string { return "http://" + s } -// hasAnyPrefixes returns true, if any of the prefixes matches string s. -func hasAnyPrefix(s string, prefix []string) bool { +// HasAnyPrefixes returns true, if any of the prefixes matches string s. +func HasAnyPrefix(s string, prefix []string) bool { for _, p := range prefix { if strings.HasPrefix(s, p) { return true |