summaryrefslogtreecommitdiffstats
path: root/helpers/url.go
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2015-02-28 18:45:02 +0100
committerbep <bjorn.erik.pedersen@gmail.com>2015-02-28 18:45:02 +0100
commit9d80ecb4d8efa1a45f649d8b75d7e2c946c09070 (patch)
tree94ec57df8c2234eed8f0dffcdf3cb62afff449d3 /helpers/url.go
parent176ce5deab2b6a71789c14a401b8f9ed10399fde (diff)
Keep trailing slash when baseUrl contains a sub path
Before this commit, .Site.BaseUrl ended up as: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub Now it becomes: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub/ Fixed #931
Diffstat (limited to 'helpers/url.go')
-rw-r--r--helpers/url.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/helpers/url.go b/helpers/url.go
index a07a3c6bd..f31e7a4e1 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -52,9 +52,8 @@ func (PathBridge) Separator() string {
var pathBridge PathBridge
-// SanitizeUrl sanitizes the input URL string.
-func SanitizeUrl(in string) string {
- s, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
+func sanitizeUrlWithFlags(in string, f purell.NormalizationFlags) string {
+ s, err := purell.NormalizeURLString(in, f)
if err != nil {
return in
}
@@ -85,6 +84,17 @@ func SanitizeUrl(in string) string {
// End temporary kludge
//return s
+
+}
+
+// SanitizeUrl sanitizes the input URL string.
+func SanitizeUrl(in string) string {
+ return sanitizeUrlWithFlags(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
+}
+
+// SanitizeUrlKeepTrailingSlash is the same as SanitizeUrl, but will keep any trailing slash.
+func SanitizeUrlKeepTrailingSlash(in string) string {
+ return sanitizeUrlWithFlags(in, purell.FlagsSafe|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
}
// Similar to MakePath, but with Unicode handling