Skip to content

Commit

Permalink
chore: path clean
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Jan 31, 2024
1 parent 8aa25bd commit f9f4c84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions local_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/gin-gonic/gin"
)

const INDEX = "index.html"

type localFileSystem struct {
http.FileSystem
root string
Expand All @@ -25,17 +23,16 @@ func LocalFile(root string, indexes bool) *localFileSystem {
}
}

func (l *localFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
name := path.Join(l.root, p)
func (l *localFileSystem) Exists(prefix string, file string) bool {
if p := strings.TrimPrefix(file, prefix); len(p) < len(file) {
name := path.Join(l.root, path.Clean(p))
stats, err := os.Stat(name)
if err != nil {
return false
}
if stats.IsDir() {
if !l.indexes {
index := path.Join(name, INDEX)
_, err := os.Stat(index)
_, err := os.Stat(path.Join(name, "index.html"))
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/soulteary/gin-static"
static "github.com/soulteary/gin-static"
"github.com/stretchr/testify/assert"
)

Expand Down

0 comments on commit f9f4c84

Please sign in to comment.