diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-25 18:46:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-28 10:56:54 +0200 |
commit | 3b478f50b7408ad78d085fa6dbc3c7a683c9d943 (patch) | |
tree | 1a2250fc8686beee6ee1d999a0d158f1edbbfe4c /hugolib/menu_test.go | |
parent | f343b8eb7877c857c23dd5f0b554024b7682de3a (diff) |
Fix HasMenuCurrent and IsDescendant/IsAncestor when comparing to itself
There may be sites in the wild that depends on the faulty behaviour of IsDescendant/IsAncestor when comparing to itself, but
* The documentation and common sense says that a thing cannot be descendant or ancestor to itself.
* The bug introduced in `HasMenuCurrent` comes directly from that confusion.
Fixes #9846
Diffstat (limited to 'hugolib/menu_test.go')
-rw-r--r-- | hugolib/menu_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 796ac3beb..4237082af 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -524,3 +524,67 @@ Blog|HasMenuCurrent: false|Page: Page(/blog/_index.md) Blog|IsMenuCurrent: false|Page: Page(/blog/_index.md) `) } + +// Issue 9846 +func TestMenuHasMenuCurrentSection(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +disableKinds = ['RSS','sitemap','taxonomy','term'] +[[menu.main]] +name = 'Home' +pageRef = '/' +weight = 1 + +[[menu.main]] +name = 'Tests' +pageRef = '/tests' +weight = 2 +[[menu.main]] +name = 'Test 1' +pageRef = '/tests/test-1' +parent = 'Tests' +weight = 1 + +-- content/tests/test-1.md -- +--- +title: "Test 1" +--- +-- layouts/_default/list.html -- +{{ range site.Menus.main }} +{{ .Name }}|{{ .URL }}|IsMenuCurrent = {{ $.IsMenuCurrent "main" . }}|HasMenuCurrent = {{ $.HasMenuCurrent "main" . }}| +{{ range .Children }} +{{ .Name }}|{{ .URL }}|IsMenuCurrent = {{ $.IsMenuCurrent "main" . }}|HasMenuCurrent = {{ $.HasMenuCurrent "main" . }}| +{{ end }} +{{ end }} + +{{/* Some tests for issue 9925 */}} +{{ $page := .Site.GetPage "tests/test-1" }} +{{ $section := site.GetPage "tests" }} + +Home IsAncestor Self: {{ site.Home.IsAncestor site.Home }} +Home IsDescendant Self: {{ site.Home.IsDescendant site.Home }} +Section IsAncestor Self: {{ $section.IsAncestor $section }} +Section IsDescendant Self: {{ $section.IsDescendant $section}} +Page IsAncestor Self: {{ $page.IsAncestor $page }} +Page IsDescendant Self: {{ $page.IsDescendant $page}} +` + + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/tests/index.html", ` +Tests|/tests/|IsMenuCurrent = true|HasMenuCurrent = false +Home IsAncestor Self: false +Home IsDescendant Self: false +Section IsAncestor Self: false +Section IsDescendant Self: false +Page IsAncestor Self: false +Page IsDescendant Self: false +`) +} |