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