mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
improve package gjson for automatic content type checking
This commit is contained in:
@ -207,8 +207,8 @@ func checkDataType(content []byte) string {
|
||||
return "json"
|
||||
} else if gregex.IsMatch(`^<.+>[\S\s]+<.+>$`, content) {
|
||||
return "xml"
|
||||
} else if gregex.IsMatch(`[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, content) ||
|
||||
gregex.IsMatch(`[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, content) {
|
||||
} else if (gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, content) || gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, content)) ||
|
||||
(gregex.IsMatch(`[\s\t\n\r]+[\w\-]+\s*:\s*".+"`, content) || gregex.IsMatch(`[\s\t\n\r]+[\w\-]+\s*:\s*\w+`, content)) {
|
||||
return "yml"
|
||||
} else if !gregex.IsMatch(`^[\s\t\n\r]*;.+`, content) &&
|
||||
!gregex.IsMatch(`[\s\t\n\r]+;.+`, content) &&
|
||||
|
||||
@ -12,11 +12,25 @@ import (
|
||||
)
|
||||
|
||||
func Test_checkDataType(t *testing.T) {
|
||||
data := []byte(`
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
data := []byte(`
|
||||
bb = """
|
||||
dig := dig; END;"""
|
||||
`)
|
||||
t.Assert(checkDataType(data), "toml")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
data := []byte(`
|
||||
# 模板引擎目录
|
||||
viewpath = "/home/www/templates/"
|
||||
# MySQL数据库配置
|
||||
[redis]
|
||||
dd = 11
|
||||
[redis]
|
||||
disk = "127.0.0.1:6379,0"
|
||||
cache = "127.0.0.1:6379,1"
|
||||
`)
|
||||
t.Assert(checkDataType(data), "toml")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user