summaryrefslogtreecommitdiffstats
path: root/tpl/urls
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2023-05-19 08:29:30 -0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-20 11:14:18 +0200
commit150d190ff041f7da905afea7f3b9ca6bd4a31a48 (patch)
treedf9d168c739494a02eeafd516a31e923fe70cc8d /tpl/urls
parent065ae003a5dc9173a1200fa1ab2d8927b002b1ab (diff)
tpl/urls: Return empty string when JoinPath has zero args
Diffstat (limited to 'tpl/urls')
-rw-r--r--tpl/urls/urls.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/tpl/urls/urls.go b/tpl/urls/urls.go
index 5de2342d4..6ae447ca2 100644
--- a/tpl/urls/urls.go
+++ b/tpl/urls/urls.go
@@ -187,16 +187,19 @@ func (ns *Namespace) AbsLangURL(s any) (template.HTML, error) {
}
// JoinPath joins the provided elements into a URL string and cleans the result
-// of any ./ or ../ elements.
+// of any ./ or ../ elements. If the argument list is empty, JoinPath returns
+// an empty string.
func (ns *Namespace) JoinPath(elements ...any) (string, error) {
+ if len(elements) == 0 {
+ return "", nil
+ }
+
var selements []string
for _, e := range elements {
switch v := e.(type) {
case []string:
- for _, e := range v {
- selements = append(selements, e)
- }
+ selements = append(selements, v...)
case []any:
for _, e := range v {
se, err := cast.ToStringE(e)