Fix permalinks to subdomains
authortummychow <tummychow@users.noreply.github.com>
Wed, 26 Mar 2014 12:03:11 +0000 (08:03 -0400)
committerspf13 <steve.francia@gmail.com>
Sun, 27 Apr 2014 05:01:28 +0000 (23:01 -0600)
If you don't have access to the root domain of your site (eg a GitHub project
page) and you try to generate custom permalinks, they must begin with a slash.
Go's URL resolution library sees the leading slash and thinks "this URL starts
at the root", just like a filesystem - so it discards your subdomain and maps
all custom permalinks from the root of your site. Fine if you control the root
domain, not so useful if you don't.

Removing the check for a leading slash fixes this problem. You can now specify
custom permalinks that do not start with a slash, and they will map safely
regardless of what subdomain you upload the generated site under.

Tests have been updated for this commit so that they continue to function.

hugolib/permalinks.go
hugolib/permalinks_test.go

index 155b1b81340a9ecb9c5ab723876ca63c7390abc1..f6c2ec80de9e0e1b5db4a58fb852c0febfae68eb 100644 (file)
@@ -26,9 +26,6 @@ var knownPermalinkAttributes map[string]PageToPermaAttribute
 
 // validate determines if a PathPattern is well-formed
 func (pp PathPattern) validate() bool {
-       if pp[0] != '/' {
-               return false
-       }
        fragments := strings.Split(string(pp[1:]), "/")
        var bail = false
        for i := range fragments {
index 019b23c2fb9902d52f2fc1352408a2ff94c2b79a..f1439d987a5f42c120de1c601c2bc20bcb948dc1 100644 (file)
@@ -14,9 +14,8 @@ var testdataPermalinks = []struct {
 }{
        {"/:year/:month/:title/", true, "/2012/04/spf13-vim-3.0-release-and-new-website/"},
        {"/:title", true, "/spf13-vim-3.0-release-and-new-website"},
-       {":title", false, ""},
+       {":title", true, "spf13-vim-3.0-release-and-new-website"},
        {"/blog/:year/:yearday/:title", true, "/blog/2012/97/spf13-vim-3.0-release-and-new-website"},
-       {":fred", false, ""},
        {"/blog/:fred", false, ""},
        {"/:year//:title", false, ""},
        {