File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ func TestDecodeBOM(t *testing.T) {
66
66
for _ , tt := range [][]byte {
67
67
[]byte ("\xff \xfe a = \" b\" " ),
68
68
[]byte ("\xfe \xff a = \" b\" " ),
69
+ []byte ("\xef \xbb \xbf a = \" b\" " ),
69
70
} {
70
71
t .Run ("" , func (t * testing.T ) {
71
72
var s struct { A string }
Original file line number Diff line number Diff line change @@ -47,9 +47,12 @@ func parse(data string) (p *parser, err error) {
47
47
}()
48
48
49
49
// Read over BOM; do this here as the lexer calls utf8.DecodeRuneInString()
50
- // which mangles stuff.
51
- if strings .HasPrefix (data , "\xff \xfe " ) || strings .HasPrefix (data , "\xfe \xff " ) {
50
+ // which mangles stuff. UTF-16 BOM isn't strictly valid, but some tools add
51
+ // it anyway.
52
+ if strings .HasPrefix (data , "\xff \xfe " ) || strings .HasPrefix (data , "\xfe \xff " ) { // UTF-16
52
53
data = data [2 :]
54
+ } else if strings .HasPrefix (data , "\xef \xbb \xbf " ) { // UTF-8
55
+ data = data [3 :]
53
56
}
54
57
55
58
// Examine first few bytes for NULL bytes; this probably means it's a UTF-16
You can’t perform that action at this time.
0 commit comments