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
path: root/tpl
diff options
context:
space:
mode:
authorCarl Johnson <me@carlmjohnson.net>2020-03-02 22:04:16 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-03-03 15:37:42 +0300
commitae383f04c806687cdae184d6138bcf51edbffcb2 (patch)
treee7e7c961527d951073a79980123f1ef9af38fcda /tpl
parentee31e61fb06bb6e26c9d66d78d8763aabd19e11d (diff)
{{ in }} should work with html.Template type
Fixes #7002
Diffstat (limited to 'tpl')
-rw-r--r--tpl/collections/collections.go15
-rw-r--r--tpl/collections/collections_test.go3
2 files changed, 13 insertions, 5 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go
index 5b9d4a700..80f4ccc07 100644
--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -292,12 +292,17 @@ func (ns *Namespace) In(l interface{}, v interface{}) (bool, error) {
return true, nil
}
}
- case reflect.String:
- if vv.Type() == lv.Type() && strings.Contains(lv.String(), vv.String()) {
- return true, nil
- }
}
- return false, nil
+ ss, err := cast.ToStringE(l)
+ if err != nil {
+ return false, nil
+ }
+
+ su, err := cast.ToStringE(v)
+ if err != nil {
+ return false, nil
+ }
+ return strings.Contains(ss, su), nil
}
// Intersect returns the common elements in the given sets, l1 and l2. l1 and
diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go
index c98f4a527..24d3b051c 100644
--- a/tpl/collections/collections_test.go
+++ b/tpl/collections/collections_test.go
@@ -345,6 +345,9 @@ func TestIn(t *testing.T) {
// Structs
{pagesVals{p3v, p2v, p3v, p2v}, p2v, true},
{pagesVals{p3v, p2v, p3v, p2v}, p4v, false},
+ // template.HTML
+ {template.HTML("this substring should be found"), "substring", true},
+ {template.HTML("this substring should not be found"), "subseastring", false},
} {
errMsg := qt.Commentf("[%d] %v", i, test)