]> Sergey Matveev's repositories - godlighty.git/commitdiff
Yet another proper escaping master
authorSergey Matveev <stargrave@stargrave.org>
Tue, 22 Apr 2025 20:43:46 +0000 (23:43 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 22 Apr 2025 20:43:53 +0000 (23:43 +0300)
dirlist.go
dirlist.tmpl
godlighty.go

index bdf47ebdf306f393c19f74c2bb1767bec22d9756..b0b2918d3697329bb7e9b9561ba3811060189d0f 100644 (file)
@@ -22,7 +22,6 @@ import (
        "os"
        "path"
        "sort"
-       "strings"
        "time"
 
        "github.com/dustin/go-humanize"
@@ -51,7 +50,7 @@ func (a ByName) Less(i, j int) bool {
 }
 
 type DirListFile struct {
-       Name    string
+       Name    template.URL
        Size    string
        Type    string
        ModTime string
@@ -75,14 +74,14 @@ func dirList(
                }
                file := DirListFile{
                        Idx:     i,
-                       Name:    fi.Name(),
+                       Name:    template.URL(fi.Name()),
                        Size:    humanize.IBytes(uint64(fi.Size())),
                        ModTime: fi.ModTime().UTC().Truncate(time.Second).Format(MTimeFmt),
                }
                if fi.IsDir() {
                        file.IsDir = true
                } else {
-                       file.Type = mediaType(file.Name, cfg.MIMEs)
+                       file.Type = mediaType(fi.Name(), cfg.MIMEs)
                }
                if (entry.Type() & fs.ModeSymlink) > 0 {
                        file.Symlink, _ = os.Readlink(path.Join(pth, fi.Name()))
@@ -106,7 +105,7 @@ func dirList(
                Files  []DirListFile
        }{
                Root:   root,
-               Dir:    strings.TrimRight(dir, "/"),
+               Dir:    dir,
                Readme: readme,
                Files:  files,
        })
index b63ccd476a489b1b73d028388d465195e1282256..8fb266fad4c545397a4e50b802bcf4a3184478cc 100644 (file)
@@ -13,7 +13,7 @@
 <tr><th>&nbsp;</th><th>Name</th><th>Mtime</th><th>Size</th><th>Type</th></tr>
 {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}}<tr>
   <td {{if .Symlink}}rowspan="2"{{end}}>{{.Idx}}</td>
-  <td><a href="{{$Root}}{{$Dir}}/{{.Name}}{{if .IsDir}}/{{end -}}"><tt>
+  <td><a href="{{$Root}}{{$Dir}}{{.Name}}{{if .IsDir}}/{{end -}}"><tt>
     {{- .Name}}{{if .IsDir}}/{{end}}</tt></a></td>
   <td><tt>{{.ModTime}}</tt></td>
   <td>{{.Size}}</td>
index c81b102716b4e60ab025843566dbecd881df2f00..895b10cb4d7223cbb4b8c8a371fe9834e4750269 100644 (file)
@@ -1,6 +1,6 @@
 // Highly-customizable HTTP, HTTP/2, HTTPS server
 package godlighty
 
-const Version = "godlighty/0.8.0"
+const Version = "godlighty/0.9.0"
 
 var BindAddr string