fix escape
This commit is contained in:
@@ -1,2 +1,12 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func EscapePath(path string) string {
|
||||
// escape %
|
||||
escapedPath := strings.ReplaceAll(path, "%", "%25")
|
||||
|
||||
// add others
|
||||
|
||||
return escapedPath
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/sirrobot01/decypharr/internal/config"
|
||||
"github.com/sirrobot01/decypharr/internal/request"
|
||||
"github.com/sirrobot01/decypharr/internal/utils"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/types"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -23,8 +24,8 @@ type fileInfo struct {
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (fi *fileInfo) Name() string { return url.PathEscape(fi.name) }
|
||||
func (fi *fileInfo) RawName() string { return fi.name }
|
||||
func (fi *fileInfo) Name() string { return utils.EscapePath(fi.name) }
|
||||
func (fi *fileInfo) RawName() string { return url.PathEscape(fi.name) }
|
||||
func (fi *fileInfo) Size() int64 { return fi.size }
|
||||
func (fi *fileInfo) Mode() os.FileMode { return fi.mode }
|
||||
func (fi *fileInfo) ModTime() time.Time { return fi.modTime }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package webdav
|
||||
|
||||
import (
|
||||
"github.com/sirrobot01/decypharr/internal/utils"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
@@ -15,8 +16,8 @@ type FileInfo struct {
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (fi *FileInfo) Name() string { return url.PathEscape(fi.name) }
|
||||
func (fi *FileInfo) RawName() string { return fi.name }
|
||||
func (fi *FileInfo) Name() string { return utils.EscapePath(fi.name) } // uses minimal escaping
|
||||
func (fi *FileInfo) RawName() string { return url.PathEscape(fi.name) } // uses full escaping
|
||||
func (fi *FileInfo) Size() int64 { return fi.size }
|
||||
func (fi *FileInfo) Mode() os.FileMode { return fi.mode }
|
||||
func (fi *FileInfo) ModTime() time.Time { return fi.modTime }
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"slices"
|
||||
@@ -104,12 +103,6 @@ func (h *Handler) getParentFiles() []os.FileInfo {
|
||||
|
||||
func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
|
||||
name = path.Clean("/" + name)
|
||||
// unescape the path
|
||||
name, err := url.PathUnescape(name)
|
||||
if err != nil {
|
||||
h.logger.Error().Err(err).Msg("Failed to unescape path")
|
||||
return nil, err
|
||||
}
|
||||
rootDir := h.getRootPath()
|
||||
|
||||
metadataOnly := ctx.Value("metadataOnly") != nil
|
||||
|
||||
@@ -113,9 +113,9 @@ const directoryTemplate = `
|
||||
{{end}}
|
||||
{{range $index, $file := .Children}}
|
||||
<li>
|
||||
<a href="{{(printf "%s/%s" $.Path $file.Name)}}">
|
||||
<a href="{{(printf "%s/%s" $.Path $file.RawName )}}">
|
||||
<span class="file-number">{{add $index 1}}.</span>
|
||||
<span class="file-name">{{$file.RawName}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-name">{{$file.Name}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-info">
|
||||
{{if not $file.IsDir}}
|
||||
{{formatSize $file.Size}}
|
||||
|
||||
Reference in New Issue
Block a user