diff --git a/encoding/gjson/gjson_api_new_load.go b/encoding/gjson/gjson_api_new_load.go index 4b1bf0d04..c96d4141c 100644 --- a/encoding/gjson/gjson_api_new_load.go +++ b/encoding/gjson/gjson_api_new_load.go @@ -207,16 +207,19 @@ func checkDataType(content []byte) string { return "json" } else if gregex.IsMatch(`^<.+>[\S\s]+<.+>$`, content) { return "xml" - } else if gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*:\s*".+"`, content) || - gregex.IsMatch(`[\s\t\n]*[\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) { return "yml" + } else if !gregex.IsMatch(`^[\s\t\n\r]*;.+`, content) && + !gregex.IsMatch(`[\s\t\n\r]+;.+`, content) && + (gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*".+"`, content) || gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*\w+`, content)) { + return "toml" } else if gregex.IsMatch(`\[[\w]+\]`, content) && - gregex.IsMatch(`[\s\t\n\[\]]*[\w\-]+\s*=\s*.+`, content) && - !gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*=*\"*.+\"`, content) { + !gregex.IsMatch(`^[\s\t\n\r]*#.+`, content) && + !gregex.IsMatch(`[\s\t\n\r]+#.+`, content) && + (gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*".+"`, content) || gregex.IsMatch(`[\s\t\n\r]*[\w\-\."]+\s*=\s*\w+`, content)) { // Must contain "[xxx]" section. return "ini" - } else if gregex.IsMatch(`[\s\t\n]*[\w\-\."]+\s*=\s*.+`, content) { - return "toml" } else { return "" } diff --git a/encoding/gjson/gjson_z_unit_load_test.go b/encoding/gjson/gjson_z_unit_load_test.go index 78c547a89..a59137e18 100644 --- a/encoding/gjson/gjson_z_unit_load_test.go +++ b/encoding/gjson/gjson_z_unit_load_test.go @@ -215,8 +215,7 @@ func Test_Load_Ini(t *testing.T) { ;注释 -[addr] -#注释 +[addr] ip = 127.0.0.1 port=9001 enable=true