From eacad9b4533f10b7947ba9a59025c5582feb2705 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 11 Aug 2020 23:22:09 +0800 Subject: [PATCH] improve package gjson for automatic content type checking --- encoding/gjson/gjson_api_new_load.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/encoding/gjson/gjson_api_new_load.go b/encoding/gjson/gjson_api_new_load.go index 9320a2b0a..4b1bf0d04 100644 --- a/encoding/gjson/gjson_api_new_load.go +++ b/encoding/gjson/gjson_api_new_load.go @@ -207,7 +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]*[\w\-]+\s*:\s*.+`, content) { + } else if gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*:\s*".+"`, content) || + gregex.IsMatch(`[\s\t\n]*[\w\-]+\s*:\s*\w+`, content) { return "yml" } else if gregex.IsMatch(`\[[\w]+\]`, content) && gregex.IsMatch(`[\s\t\n\[\]]*[\w\-]+\s*=\s*.+`, content) &&