summaryrefslogtreecommitdiffstats
path: root/helpers/url.go
diff options
context:
space:
mode:
authorAnthony Fok <foka@debian.org>2015-02-16 11:26:54 -0700
committerspf13 <steve.francia@gmail.com>2015-02-17 12:31:39 -0500
commitc4393257e804804b5e1db5ea82fc24ddf68255b4 (patch)
treec2ca7406ab478189217de24fcf3ccfe0aba6f058 /helpers/url.go
parent41c0e82f95706eea320d75e759256627702237e6 (diff)
Adapt to relative path bug fix in purell
Temporary workaround for the bug fix and resulting behavioral change in purell.NormalizeURLString(): a leading '/' was inadvertently to relative links, but no longer, see #878. I think the real solution is to allow Hugo to make relative URL with relative path, e.g. "../../post/hello-again/", as wished by users in issues #157, #622, etc., without forcing relative URLs to begin with '/'. Once the fixes are in, let's remove this kludge and restore SanitizeUrl() to the way it was. Fixes #878
Diffstat (limited to 'helpers/url.go')
-rw-r--r--helpers/url.go32
1 files changed, 29 insertions, 3 deletions
diff --git a/helpers/url.go b/helpers/url.go
index 380ba29c2..a07a3c6bd 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -1,4 +1,4 @@
-// Copyright © 2013 Steve Francia <spf@spf13.com>.
+// Copyright © 2013-2015 Steve Francia <spf@spf13.com>.
//
// Licensed under the Simple Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -54,11 +54,37 @@ var pathBridge PathBridge
// SanitizeUrl sanitizes the input URL string.
func SanitizeUrl(in string) string {
- url, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
+ s, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
if err != nil {
return in
}
- return url
+
+ // Temporary workaround for the bug fix and resulting
+ // behavioral change in purell.NormalizeURLString():
+ // a leading '/' was inadvertently to relative links,
+ // but no longer, see #878.
+ //
+ // I think the real solution is to allow Hugo to
+ // make relative URL with relative path,
+ // e.g. "../../post/hello-again/", as wished by users
+ // in issues #157, #622, etc., without forcing
+ // relative URLs to begin with '/'.
+ // Once the fixes are in, let's remove this kludge
+ // and restore SanitizeUrl() to the way it was.
+ // -- @anthonyfok, 2015-02-16
+ //
+ // Begin temporary kludge
+ u, err := url.Parse(s)
+ if err != nil {
+ panic(err)
+ }
+ if !strings.HasPrefix(u.Path, "/") {
+ u.Path = "/" + u.Path
+ }
+ return u.String()
+ // End temporary kludge
+
+ //return s
}
// Similar to MakePath, but with Unicode handling