mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
Merge branch 'master' of https://github.com/gogf/gf
This commit is contained in:
@ -10,9 +10,10 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/internal/json"
|
||||
|
||||
"github.com/gogf/gf/encoding/gini"
|
||||
"github.com/gogf/gf/encoding/gtoml"
|
||||
"github.com/gogf/gf/encoding/gxml"
|
||||
@ -188,6 +189,12 @@ func LoadContent(data interface{}, safe ...bool) (*Json, error) {
|
||||
if len(content) == 0 {
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
|
||||
//ignore UTF8-BOM
|
||||
if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF {
|
||||
content = content[3:]
|
||||
}
|
||||
|
||||
return doLoadContent(checkDataType(content), content, safe...)
|
||||
|
||||
}
|
||||
|
||||
@ -9,11 +9,12 @@
|
||||
package gcfg_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
|
||||
"github.com/gogf/gf/encoding/gjson"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/os/gcfg"
|
||||
@ -475,3 +476,13 @@ func TestCfg_Config(t *testing.T) {
|
||||
t.Assert(gcfg.GetContent("name"), "")
|
||||
})
|
||||
}
|
||||
|
||||
func TestCfg_With_UTF8_BOM(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
cfg := g.Cfg("test-cfg-with-utf8-bom")
|
||||
t.Assert(cfg.SetPath("testdata"), nil)
|
||||
cfg.SetFileName("cfg-with-utf8-bom.toml")
|
||||
t.Assert(cfg.GetInt("test.testInt"), 1)
|
||||
t.Assert(cfg.GetString("test.testStr"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
4
os/gcfg/testdata/cfg-with-utf8-bom.toml
vendored
Normal file
4
os/gcfg/testdata/cfg-with-utf8-bom.toml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
[test]
|
||||
testInt=1
|
||||
testStr="test"
|
||||
Reference in New Issue
Block a user