Skip to content

Commit 04390c5

Browse files
committed
fix: windows判断文件路径
1 parent 84d59c8 commit 04390c5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

engine/robot/http.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package robot
33
import (
44
"fmt"
55
"net/http"
6-
"path/filepath"
6+
"runtime"
77
"strings"
88

99
"github.com/gin-gonic/gin"
@@ -53,10 +53,19 @@ func runServer(c *Config) {
5353
c.String(http.StatusInternalServerError, "Warning: 非法访问")
5454
return
5555
}
56-
if !strings.HasPrefix(filename, filepath.Join("data", "plugins")) && !strings.HasPrefix(filename, filepath.Join(".", "data", "plugins")) {
57-
log.Errorf("[http] 非法访问静态文件: %s", filename)
58-
c.String(http.StatusInternalServerError, "Warning: 非法访问")
59-
return
56+
switch runtime.GOOS {
57+
case "windows":
58+
if !strings.HasPrefix(filename, "data\\plugins") && !strings.HasPrefix(filename, ".\\data\\plugins") {
59+
log.Errorf("[http] 非法访问静态文件: %s", filename)
60+
c.String(http.StatusInternalServerError, "Warning: 非法访问")
61+
return
62+
}
63+
default:
64+
if !strings.HasPrefix(filename, "data/plugins") && !strings.HasPrefix(filename, "./data/plugins") {
65+
log.Errorf("[http] 非法访问静态文件: %s", filename)
66+
c.String(http.StatusInternalServerError, "Warning: 非法访问")
67+
return
68+
}
6069
}
6170
c.File(filename)
6271
})

0 commit comments

Comments
 (0)