Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2022-01-30 05:34:27 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-10 22:42:31 +0300
commitd1109f590adf78afb3052e9aa3b89d093c08db47 (patch)
treee5bf1b319f1ab8e1b835aab8d98bb8ce8ea5e15a /resources
parenta7d182cea1f44a2444f543fd1e7beb01e128a892 (diff)
Fix validation of Page Kind in cascade target map
Fixes #8888
Diffstat (limited to 'resources')
-rw-r--r--resources/page/page_matcher.go15
-rw-r--r--resources/page/page_matcher_test.go7
2 files changed, 17 insertions, 5 deletions
diff --git a/resources/page/page_matcher.go b/resources/page/page_matcher.go
index 0c4c2d0e2..4c1409e9e 100644
--- a/resources/page/page_matcher.go
+++ b/resources/page/page_matcher.go
@@ -17,11 +17,10 @@ import (
"path/filepath"
"strings"
- "github.com/pkg/errors"
-
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/hugofs/glob"
"github.com/mitchellh/mapstructure"
+ "github.com/pkg/errors"
)
// A PageMatcher can be used to match a Page with Glob patterns.
@@ -114,8 +113,16 @@ func DecodePageMatcher(m interface{}, v *PageMatcher) error {
v.Kind = strings.ToLower(v.Kind)
if v.Kind != "" {
- if _, found := kindMap[v.Kind]; !found {
- return errors.Errorf("%q is not a valid Page Kind", v.Kind)
+ g, _ := glob.GetGlob(v.Kind)
+ found := false
+ for _, k := range kindMap {
+ if g.Match(k) {
+ found = true
+ break
+ }
+ }
+ if !found {
+ return errors.Errorf("%q did not match a valid Page Kind", v.Kind)
}
}
diff --git a/resources/page/page_matcher_test.go b/resources/page/page_matcher_test.go
index 745a6aa32..aaef27eaa 100644
--- a/resources/page/page_matcher_test.go
+++ b/resources/page/page_matcher_test.go
@@ -54,7 +54,12 @@ func TestPageMatcher(t *testing.T) {
c.Run("Decode", func(c *qt.C) {
var v PageMatcher
- c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "foo"}, &v), qt.Not((qt.IsNil)))
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "foo"}, &v), qt.Not(qt.IsNil))
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{foo,bar}"}, &v), qt.Not(qt.IsNil))
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "taxonomy"}, &v), qt.IsNil)
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{taxonomy,foo}"}, &v), qt.IsNil)
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{taxonomy,term}"}, &v), qt.IsNil)
+ c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "*"}, &v), qt.IsNil)
c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "home", "path": filepath.FromSlash("/a/b/**")}, &v), qt.IsNil)
c.Assert(v, qt.Equals, PageMatcher{Kind: "home", Path: "/a/b/**"})
})