|
1 |
| -// Copyright © 2013 Steve Francia <[email protected]>. |
| 1 | +// Copyright © 2013-2015 Steve Francia <[email protected]>. |
2 | 2 | //
|
3 | 3 | // Licensed under the Simple Public License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
@@ -54,11 +54,37 @@ var pathBridge PathBridge
|
54 | 54 |
|
55 | 55 | // SanitizeUrl sanitizes the input URL string.
|
56 | 56 | func SanitizeUrl(in string) string {
|
57 |
| - url, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator) |
| 57 | + s, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator) |
58 | 58 | if err != nil {
|
59 | 59 | return in
|
60 | 60 | }
|
61 |
| - return url |
| 61 | + |
| 62 | + // Temporary workaround for the bug fix and resulting |
| 63 | + // behavioral change in purell.NormalizeURLString(): |
| 64 | + // a leading '/' was inadvertently to relative links, |
| 65 | + // but no longer, see #878. |
| 66 | + // |
| 67 | + // I think the real solution is to allow Hugo to |
| 68 | + // make relative URL with relative path, |
| 69 | + // e.g. "../../post/hello-again/", as wished by users |
| 70 | + // in issues #157, #622, etc., without forcing |
| 71 | + // relative URLs to begin with '/'. |
| 72 | + // Once the fixes are in, let's remove this kludge |
| 73 | + // and restore SanitizeUrl() to the way it was. |
| 74 | + // -- @anthonyfok, 2015-02-16 |
| 75 | + // |
| 76 | + // Begin temporary kludge |
| 77 | + u, err := url.Parse(s) |
| 78 | + if err != nil { |
| 79 | + panic(err) |
| 80 | + } |
| 81 | + if !strings.HasPrefix(u.Path, "/") { |
| 82 | + u.Path = "/" + u.Path |
| 83 | + } |
| 84 | + return u.String() |
| 85 | + // End temporary kludge |
| 86 | + |
| 87 | + //return s |
62 | 88 | }
|
63 | 89 |
|
64 | 90 | // Similar to MakePath, but with Unicode handling
|
|
0 commit comments