mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
fix: safety text validate rule #383
This commit is contained in:
parent
189f623994
commit
6302454826
20 changed files with 191 additions and 219 deletions
30
internal/validation/safety_text_test.go
Normal file
30
internal/validation/safety_text_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
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