diff options
author | spf13 <steve.francia@gmail.com> | 2014-04-08 06:02:08 +0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-04-08 06:02:08 +0400 |
commit | ad34be9d77f8abf948d36de4498e8955a02bbec6 (patch) | |
tree | 131ce5ab66afa2b8a010ae9bd8b3c9ad5083bf18 /helpers | |
parent | a6170154cf8b82243510682c73c55a75ff201805 (diff) |
strip trailing baseurl slash. Added a new template function "sanitizeurl" which ensures no double slashes. Fixed #221
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/url.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/helpers/url.go b/helpers/url.go index ffafe7af0..d7f99f4f5 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -16,8 +16,18 @@ package helpers import ( "net/url" "path" + + "github.com/PuerkitoBio/purell" ) +func SanitizeUrl(in string) string { + url, err := purell.NormalizeURLString(in, purell.FlagsUsuallySafeGreedy|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator) + if err != nil { + return in + } + return url +} + // Similar to MakePath, but with Unicode handling // Example: // uri: Vim (text editor) @@ -55,6 +65,7 @@ func MakePermalink(host, plink string) *url.URL { } func UrlPrep(ugly bool, in string) string { + in = SanitizeUrl(in) if ugly { return Uglify(in) } else { |