Skip to content

Commit 88d9546

Browse files
committed
fixup! Fix go-gitea#16252 - Equivalent to go-gitea#16268
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 339a74b commit 88d9546

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

models/helper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
package models
66

7+
import (
8+
jsoniter "github.com/json-iterator/go"
9+
)
10+
711
func keysInt64(m map[int64]struct{}) []int64 {
812
keys := make([]int64, 0, len(m))
913
for k := range m {
@@ -27,3 +31,14 @@ func valuesUser(m map[int64]*User) []*User {
2731
}
2832
return values
2933
}
34+
35+
// JSONUnmarshalIgnoreErroneousBOM - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
36+
// possible that a Blob may gain an unwanted prefix of 0xff 0xfe.
37+
func JSONUnmarshalIgnoreErroneousBOM(bs []byte, v interface{}) error {
38+
json := jsoniter.ConfigCompatibleWithStandardLibrary
39+
err := json.Unmarshal(bs, &v)
40+
if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe {
41+
err = json.Unmarshal(bs[2:], &v)
42+
}
43+
return err
44+
}

models/login_source.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/timeutil"
14-
jsoniter "github.com/json-iterator/go"
1514

1615
"xorm.io/xorm"
1716
"xorm.io/xorm/convert"
@@ -127,17 +126,6 @@ func Cell2Int64(val xorm.Cell) int64 {
127126
return (*val).(int64)
128127
}
129128

130-
// JsonUnmarshalIgnoreErroneousBOM - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
131-
// possible that a Blob may gain an unwanted prefix of 0xff 0xfe.
132-
func JsonUnmarshalIgnoreErroneousBOM(bs []byte, v interface{}) error {
133-
json := jsoniter.ConfigCompatibleWithStandardLibrary
134-
err := json.Unmarshal(bs, &v)
135-
if err != nil && len(bs) > 2 && bs[0] == 0xff && bs[1] == 0xfe {
136-
err = json.Unmarshal(bs[2:], &v)
137-
}
138-
return err
139-
}
140-
141129
// BeforeSet is invoked from XORM before setting the value of a field of this object.
142130
func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) {
143131
if colName == "type" {

models/repo_unit.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type UnitConfig struct{}
2828

2929
// FromDB fills up a UnitConfig from serialized format.
3030
func (cfg *UnitConfig) FromDB(bs []byte) error {
31-
return JsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
31+
return JSONUnmarshalIgnoreErroneousBOM(bs, &cfg)
3232
}
3333

3434
// ToDB exports a UnitConfig to a serialized format.
@@ -44,7 +44,7 @@ type ExternalWikiConfig struct {
4444

4545
// FromDB fills up a ExternalWikiConfig from serialized format.
4646
func (cfg *ExternalWikiConfig) FromDB(bs []byte) error {
47-
return JsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
47+
return JSONUnmarshalIgnoreErroneousBOM(bs, &cfg)
4848
}
4949

5050
// ToDB exports a ExternalWikiConfig to a serialized format.
@@ -62,7 +62,7 @@ type ExternalTrackerConfig struct {
6262

6363
// FromDB fills up a ExternalTrackerConfig from serialized format.
6464
func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
65-
return JsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
65+
return JSONUnmarshalIgnoreErroneousBOM(bs, &cfg)
6666
}
6767

6868
// ToDB exports a ExternalTrackerConfig to a serialized format.
@@ -80,7 +80,7 @@ type IssuesConfig struct {
8080

8181
// FromDB fills up a IssuesConfig from serialized format.
8282
func (cfg *IssuesConfig) FromDB(bs []byte) error {
83-
return JsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
83+
return JSONUnmarshalIgnoreErroneousBOM(bs, &cfg)
8484
}
8585

8686
// ToDB exports a IssuesConfig to a serialized format.
@@ -103,7 +103,7 @@ type PullRequestsConfig struct {
103103

104104
// FromDB fills up a PullRequestsConfig from serialized format.
105105
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
106-
return JsonUnmarshalIgnoreErroneousBOM(bs, &cfg)
106+
return JSONUnmarshalIgnoreErroneousBOM(bs, &cfg)
107107
}
108108

109109
// ToDB exports a PullRequestsConfig to a serialized format.

services/auth/source/ldap/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (source *Source) FromDB(bs []byte) error {
6969
Source: source,
7070
}
7171

72-
err := models.JsonUnmarshalIgnoreErroneousBOM(bs, &wrapped)
72+
err := models.JSONUnmarshalIgnoreErroneousBOM(bs, &wrapped)
7373
if err != nil {
7474
return err
7575
}

services/auth/source/oauth2/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Source struct {
3232

3333
// FromDB fills up an OAuth2Config from serialized format.
3434
func (source *Source) FromDB(bs []byte) error {
35-
return models.JsonUnmarshalIgnoreErroneousBOM(bs, source)
35+
return models.JSONUnmarshalIgnoreErroneousBOM(bs, source)
3636
}
3737

3838
// ToDB exports an SMTPConfig to a serialized format.

services/auth/source/pam/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Source struct {
2828

2929
// FromDB fills up a PAMConfig from serialized format.
3030
func (source *Source) FromDB(bs []byte) error {
31-
return models.JsonUnmarshalIgnoreErroneousBOM(bs, &source)
31+
return models.JSONUnmarshalIgnoreErroneousBOM(bs, &source)
3232
}
3333

3434
// ToDB exports a PAMConfig to a serialized format.

services/auth/source/smtp/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Source struct {
3232

3333
// FromDB fills up an SMTPConfig from serialized format.
3434
func (source *Source) FromDB(bs []byte) error {
35-
return models.JsonUnmarshalIgnoreErroneousBOM(bs, source)
35+
return models.JSONUnmarshalIgnoreErroneousBOM(bs, source)
3636
}
3737

3838
// ToDB exports an SMTPConfig to a serialized format.

services/auth/source/sspi/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Source struct {
2727

2828
// FromDB fills up an SSPIConfig from serialized format.
2929
func (cfg *Source) FromDB(bs []byte) error {
30-
return models.JsonUnmarshalIgnoreErroneousBOM(bs, cfg)
30+
return models.JSONUnmarshalIgnoreErroneousBOM(bs, cfg)
3131
}
3232

3333
// ToDB exports an SSPIConfig to a serialized format.

0 commit comments

Comments
 (0)