1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

hugolib: Normalize permalink path segments

When constructing permalinks, ensure that path segments are normalized
with PathSpec.MakeSegment instead of PathSpec.URLize.

Fixes #4926
This commit is contained in:
Cameron Moore
2018-09-14 04:35:26 -05:00
committed by Bjørn Erik Pedersen
parent 555a5612b2
commit 06976ebb87
2 changed files with 30 additions and 30 deletions

View File

@@ -19,36 +19,26 @@ import (
)
// testdataPermalinks is used by a couple of tests; the expandsTo content is
// subject to the data in SIMPLE_PAGE_JSON.
// subject to the data in simplePageJSON.
var testdataPermalinks = []struct {
spec string
valid bool
expandsTo string
}{
//{"/: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"},
//{"/blog/:year/:yearday/:title", true, "/blog/2012/97/spf13-vim-3.0-release-and-new-website"},
{":title", true, "spf13-vim-3.0-release-and-new-website"},
{"/:year-:month-:title", true, "/2012-04-spf13-vim-3.0-release-and-new-website"},
{"/blog/:year-:month-:title", true, "/blog/2012-04-spf13-vim-3.0-release-and-new-website"},
{"/blog-:year-:month-:title", true, "/blog-2012-04-spf13-vim-3.0-release-and-new-website"},
//{"/blog/:fred", false, ""},
//{"/:year//:title", false, ""},
//{
//"/:section/:year/:month/:day/:weekdayname/:yearday/:title",
//true,
//"/blue/2012/04/06/Friday/97/spf13-vim-3.0-release-and-new-website",
//},
//{
//"/:weekday/:weekdayname/:month/:monthname",
//true,
//"/5/Friday/04/April",
//},
//{
//"/:slug/:title",
//true,
//"/spf13-vim-3-0-release-and-new-website/spf13-vim-3.0-release-and-new-website",
//},
{"/:year/:yearday/:month/:monthname/:day/:weekday/:weekdayname/", true, "/2012/97/04/April/06/5/Friday/"}, // Dates
{"/:section/", true, "/blue/"}, // Section
{"/:title/", true, "/spf13-vim-3.0-release-and-new-website/"}, // Title
{"/:slug/", true, "/spf13-vim-3-0-release-and-new-website/"}, // Slug
{"/:filename/", true, "/test-page/"}, // Filename
// TODO(moorereason): need test scaffolding for this.
//{"/:sections/", false, "/blue/"}, // Sections
// Failures
{"/blog/:fred", false, ""},
{"/:year//:title", false, ""},
}
func TestPermalinkValidation(t *testing.T) {
@@ -75,7 +65,7 @@ func TestPermalinkExpansion(t *testing.T) {
page, err := s.NewPageFrom(strings.NewReader(simplePageJSON), "blue/test-page.md")
if err != nil {
t.Fatalf("failed before we began, could not parse SIMPLE_PAGE_JSON: %s", err)
t.Fatalf("failed before we began, could not parse simplePageJSON: %s", err)
}
for _, item := range testdataPermalinks {
if !item.valid {