diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-05-21 11:25:00 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-05-24 12:35:45 +0200 |
commit | a985efcecf44afe1d252690ec0a00cf077974f44 (patch) | |
tree | 792e19ede943310f091977edb36962d1eee596f9 /hugolib/pagecollections.go | |
parent | 6c3c6686f5d3c7155e2d455b07ac8ab70f42cb88 (diff) |
Fix GetPage on section/bundle name overlaps
In the internal Radix we stored the directory based nodes without a traling slash, e.g. `/blog`.
The original motivation was probably to make it easy to do prefix searching: Give me all ancestors.
This, however have lead to some ambigouty with overlapping directory names.
This particular problem was, however, not possible to work around in an easy way, so from now we store these as `/blog/`.
Fixes #7301
Diffstat (limited to 'hugolib/pagecollections.go')
-rw-r--r-- | hugolib/pagecollections.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go index 7cdac7453..49378452f 100644 --- a/hugolib/pagecollections.go +++ b/hugolib/pagecollections.go @@ -169,18 +169,20 @@ func (c *PageCollections) getPageNew(context page.Page, ref string) (page.Page, func (c *PageCollections) getSectionOrPage(ref string) (*contentNode, string) { var n *contentNode - s, v, found := c.pageMap.sections.LongestPrefix(ref) + pref := helpers.AddTrailingSlash(ref) + s, v, found := c.pageMap.sections.LongestPrefix(pref) if found { n = v.(*contentNode) } - if found && s == ref { + if found && s == pref { // A section return n, "" } m := c.pageMap + filename := strings.TrimPrefix(strings.TrimPrefix(ref, s), "/") langSuffix := "." + m.s.Lang() @@ -224,9 +226,11 @@ func shouldDoSimpleLookup(ref string) bool { func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref string) (*contentNode, error) { ref = filepath.ToSlash(strings.ToLower(strings.TrimSpace(ref))) + if ref == "" { ref = "/" } + inRef := ref navUp := strings.HasPrefix(ref, "..") var doSimpleLookup bool @@ -275,9 +279,11 @@ func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref } // Check if it's a taxonomy node - s, v, found := m.taxonomies.LongestPrefix(ref) + pref := helpers.AddTrailingSlash(ref) + s, v, found := m.taxonomies.LongestPrefix(pref) + if found { - if !m.onSameLevel(ref, s) { + if !m.onSameLevel(pref, s) { return nil, nil } return v.(*contentNode), nil |