Fix permalinks to subdomains

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.
This commit is contained in:
tummychow 2014-03-26 08:03:11 -04:00 committed by spf13
parent bdf7cd9f9d
commit 2e954d8551
2 changed files with 1 additions and 5 deletions

View file

@ -26,9 +26,6 @@ var knownPermalinkAttributes map[string]PageToPermaAttribute
// validate determines if a PathPattern is well-formed // validate determines if a PathPattern is well-formed
func (pp PathPattern) validate() bool { func (pp PathPattern) validate() bool {
if pp[0] != '/' {
return false
}
fragments := strings.Split(string(pp[1:]), "/") fragments := strings.Split(string(pp[1:]), "/")
var bail = false var bail = false
for i := range fragments { for i := range fragments {

View file

@ -14,9 +14,8 @@ var testdataPermalinks = []struct {
}{ }{
{"/:year/:month/:title/", true, "/2012/04/spf13-vim-3.0-release-and-new-website/"}, {"/: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", 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"}, {"/blog/:year/:yearday/:title", true, "/blog/2012/97/spf13-vim-3.0-release-and-new-website"},
{":fred", false, ""},
{"/blog/:fred", false, ""}, {"/blog/:fred", false, ""},
{"/:year//:title", false, ""}, {"/:year//:title", false, ""},
{ {