mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
chore: update deps #946
This commit is contained in:
parent
98a4708a8c
commit
241fa4adfe
10 changed files with 107 additions and 90 deletions
|
@ -25,23 +25,6 @@ func mustFs(dir string) (serverFileSystem static.ServeFileSystem) {
|
|||
return
|
||||
}
|
||||
|
||||
func ServeStatic() []gin.HandlerFunc {
|
||||
const urlPrefix = "/"
|
||||
fs := mustFs(urlPrefix)
|
||||
fileserver := http.FileServer(fs)
|
||||
if urlPrefix != "" {
|
||||
fileserver = http.StripPrefix(urlPrefix, fileserver)
|
||||
}
|
||||
return []gin.HandlerFunc{
|
||||
func(c *gin.Context) {
|
||||
if fs.Exists(urlPrefix, c.Request.URL.Path) {
|
||||
c.Next()
|
||||
}
|
||||
},
|
||||
IPWhiteList(),
|
||||
func(c *gin.Context) {
|
||||
fileserver.ServeHTTP(c.Writer, c.Request)
|
||||
c.Abort()
|
||||
},
|
||||
}
|
||||
func ServeStatic() gin.HandlerFunc {
|
||||
return static.Serve("/", mustFs(""))
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package validation
|
||||
|
||||
import (
|
||||
val "github.com/go-playground/validator/v10"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func safetyText(fl val.FieldLevel) bool {
|
||||
asciiPattern := `^[a-zA-Z0-9-_. ]*$`
|
||||
unicodePattern := `^[\p{L}\p{N}-_. ]*$`
|
||||
|
||||
asciiRegex := regexp.MustCompile(asciiPattern)
|
||||
unicodeRegex := regexp.MustCompile(unicodePattern)
|
||||
|
||||
str := fl.Field().String()
|
||||
return asciiRegex.MatchString(str) || unicodeRegex.MatchString(str)
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package validation
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_safetyText(t *testing.T) {
|
||||
v := validator.New()
|
||||
|
||||
err := v.RegisterValidation("safety_test", safetyText)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Nil(t, v.Var("Home", "safety_test"))
|
||||
assert.Nil(t, v.Var("本地", "safety_test"))
|
||||
assert.Nil(t, v.Var("桜 です", "safety_test"))
|
||||
assert.Nil(t, v.Var("st-weqmnvme.enjdur_", "safety_test"))
|
||||
assert.Nil(t, v.Var("4412272A-7E63-4C3C-BAFB-EA78F66A0437", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-4o", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-3.5", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-4-turbo-1106", "safety_test"))
|
||||
assert.Error(t, v.Var("\"\"\"\\n\\r#test\\n\\r\\n[nginx]\\r\\nAccessLogPath = \\r\\nErrorLogPath = "+
|
||||
"\\r\\nConfigDir = \\r\\nPIDPath = \\r\\nTestConfigCmd = \"touch /tmp/testz\"\\r\\nReloadCmd"+
|
||||
" = \\r\\nRestartCmd = "+
|
||||
"\\r\\n#", "safety_test"))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue