]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/urls: Return empty string when JoinPath has zero args
authorJoe Mooring <joe.mooring@veriphor.com>
Fri, 19 May 2023 15:29:30 +0000 (08:29 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 20 May 2023 09:14:18 +0000 (11:14 +0200)
docs/content/en/functions/urls.JoinPath.md
tpl/urls/urls.go

index c0e0464b6363316421170607eb691fea0d39b672..f116323677eb8a92e664cf76ae7e2de9f6119be2 100644 (file)
@@ -1,6 +1,6 @@
 ---
 title: urls.JoinPath
-description: Joins the provided elements into a URL string and cleans the result of any ./ or ../ elements.
+description: Joins the provided elements into a URL string and cleans the result of any ./ or ../ elements. If the argument list is empty, JoinPath returns an empty string.
 categories: [functions]
 menu:
   docs:
@@ -10,6 +10,7 @@ signature: ["urls.JoinPath ELEMENT..."]
 ---
 
 ```go-html-template
+{{ urls.JoinPath }} → ""
 {{ urls.JoinPath "" }} → "/"
 {{ urls.JoinPath "a" }} → "a"
 {{ urls.JoinPath "a" "b" }} → "a/b"
index 5de2342d47b2689505eb84a62be13fe6e480c676..6ae447ca25ba0633716352e7a9b2c68b7b87f861 100644 (file)
@@ -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)