aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-03-15 13:12:25 +0100
committerBjørn Erik Pedersen <[email protected]>2024-03-15 16:45:53 +0100
commitb40f3c7df6bc89efaaadddec7d2cc291557b2ee9 (patch)
tree462c47ca383bf09a9c1c7f57c42793cb1072c0ad /tpl
parent57206e72749966f36c6e731c3f5ce7d9b5b11464 (diff)
downloadhugo-b40f3c7df6bc89efaaadddec7d2cc291557b2ee9.tar.gz
hugo-b40f3c7df6bc89efaaadddec7d2cc291557b2ee9.zip
Fix intersect and similar for term entry page collections
Fixes #12254
Diffstat (limited to 'tpl')
-rw-r--r--tpl/collections/collections.go8
-rw-r--r--tpl/collections/collections_integration_test.go48
-rw-r--r--tpl/collections/reflect_helpers.go3
3 files changed, 54 insertions, 5 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go
index 2107cf5a0..edec536ef 100644
--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -617,10 +617,10 @@ type intersector struct {
}
func (i *intersector) appendIfNotSeen(v reflect.Value) {
- vi := v.Interface()
- if !i.seen[vi] {
+ k := normalize(v)
+ if !i.seen[k] {
i.r = reflect.Append(i.r, v)
- i.seen[vi] = true
+ i.seen[k] = true
}
}
@@ -638,7 +638,7 @@ func (i *intersector) handleValuePair(l1vv, l2vv reflect.Value) {
i.appendIfNotSeen(l1vv)
}
case kind == reflect.Ptr, kind == reflect.Struct:
- if l1vv.Interface() == l2vv.Interface() {
+ if types.Unwrapv(l1vv.Interface()) == types.Unwrapv(l2vv.Interface()) {
i.appendIfNotSeen(l1vv)
}
case kind == reflect.Interface:
diff --git a/tpl/collections/collections_integration_test.go b/tpl/collections/collections_integration_test.go
index 1bcabb447..3bcd4effb 100644
--- a/tpl/collections/collections_integration_test.go
+++ b/tpl/collections/collections_integration_test.go
@@ -230,3 +230,51 @@ boolf = false
"false",
)
}
+
+func TestTermEntriesCollectionsIssue12254(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+capitalizeListTitles = false
+disableKinds = ['rss','sitemap']
+-- content/p1.md --
+---
+title: p1
+categories: [cat-a]
+tags: ['tag-b','tag-a','tag-c']
+---
+-- content/p2.md --
+---
+title: p2
+categories: [cat-a]
+tags: ['tag-b','tag-a']
+---
+-- content/p3.md --
+---
+title: p3
+categories: [cat-a]
+tags: ['tag-b']
+---
+-- layouts/_default/term.html --
+{{ $list1 := .Pages }}
+{{ range $i, $e := site.Taxonomies.tags.ByCount }}
+{{ $list2 := .Pages }}
+{{ $i }}: List1: {{ len $list1 }}|
+{{ $i }}: List2: {{ len $list2 }}|
+{{ $i }}: Intersect: {{ intersect $.Pages .Pages | len }}|
+{{ $i }}: Union: {{ union $.Pages .Pages | len }}|
+{{ $i }}: SymDiff: {{ symdiff $.Pages .Pages | len }}|
+{{ $i }}: Uniq: {{ append $.Pages .Pages | uniq | len }}|
+{{ end }}
+
+
+`
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/categories/cat-a/index.html",
+ "0: List1: 3|\n0: List2: 3|\n0: Intersect: 3|\n0: Union: 3|\n0: SymDiff: 0|\n0: Uniq: 3|\n\n\n1: List1: 3|",
+ "1: List2: 2|\n1: Intersect: 2|\n1: Union: 3|\n1: SymDiff: 1|\n1: Uniq: 3|\n\n\n2: List1: 3|\n2: List2: 1|",
+ "2: Intersect: 1|\n2: Union: 3|\n2: SymDiff: 2|\n2: Uniq: 3|",
+ )
+}
diff --git a/tpl/collections/reflect_helpers.go b/tpl/collections/reflect_helpers.go
index 56909d30e..4687acdde 100644
--- a/tpl/collections/reflect_helpers.go
+++ b/tpl/collections/reflect_helpers.go
@@ -18,6 +18,7 @@ import (
"fmt"
"reflect"
+ "github.com/gohugoio/hugo/common/types"
"github.com/mitchellh/hashstructure"
)
@@ -60,7 +61,7 @@ func normalize(v reflect.Value) any {
return f
}
}
- return v.Interface()
+ return types.Unwrapv(v.Interface())
}
// collects identities from the slices in seqs into a set. Numeric values are normalized,