From: Sergey Matveev Date: Tue, 22 Apr 2025 20:43:46 +0000 (+0300) Subject: Yet another proper escaping X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=godlighty.git Yet another proper escaping --- diff --git a/dirlist.go b/dirlist.go index bdf47eb..b0b2918 100644 --- a/dirlist.go +++ b/dirlist.go @@ -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, }) diff --git a/dirlist.tmpl b/dirlist.tmpl index b63ccd4..8fb266f 100644 --- a/dirlist.tmpl +++ b/dirlist.tmpl @@ -13,7 +13,7 @@  NameMtimeSizeType {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}} {{.Idx}} - + {{- .Name}}{{if .IsDir}}/{{end}} {{.ModTime}} {{.Size}} diff --git a/godlighty.go b/godlighty.go index c81b102..895b10c 100644 --- a/godlighty.go +++ b/godlighty.go @@ -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