Migrate to use jsoniter instead of encoding/json (#14841)
* Migrate to use jsoniter * fix tests * update gitea.com/go-chi/binding Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/format"
|
||||
@@ -20,6 +19,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,6 +51,7 @@ func (e Emoji) MarshalJSON() ([]byte, error) {
|
||||
x.UnicodeVersion = ""
|
||||
x.Description = ""
|
||||
x.SkinTones = false
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(x)
|
||||
}
|
||||
|
||||
@@ -101,6 +103,7 @@ func generate() ([]byte, error) {
|
||||
|
||||
// unmarshal
|
||||
var data Gemoji
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+2
-1
@@ -6,7 +6,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
archiver "github.com/mholt/archiver/v3"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@@ -296,6 +296,7 @@ func runDump(ctx *cli.Context) error {
|
||||
var excludes []string
|
||||
if setting.Cfg.Section("session").Key("PROVIDER").Value() == "file" {
|
||||
var opts session.Options
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err = json.Unmarshal([]byte(setting.SessionConfig.ProviderConfig), &opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,7 +6,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/kballard/go-shellquote"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@@ -255,6 +255,7 @@ func runServ(c *cli.Context) error {
|
||||
}
|
||||
tokenAuthentication.Header["Authorization"] = fmt.Sprintf("Bearer %s", tokenString)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
err = enc.Encode(tokenAuthentication)
|
||||
if err != nil {
|
||||
|
||||
@@ -6,7 +6,7 @@ require (
|
||||
cloud.google.com/go v0.78.0 // indirect
|
||||
code.gitea.io/gitea-vet v0.2.1
|
||||
code.gitea.io/sdk/gitea v0.13.2
|
||||
gitea.com/go-chi/binding v0.0.0-20210113025129-03f1d313373c
|
||||
gitea.com/go-chi/binding v0.0.0-20210301195521-1fe1c9a555e7
|
||||
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e
|
||||
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e
|
||||
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
|
||||
@@ -66,6 +66,7 @@ require (
|
||||
github.com/issue9/assert v1.3.2 // indirect
|
||||
github.com/issue9/identicon v1.0.1
|
||||
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
|
||||
github.com/json-iterator/go v1.1.10
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
|
||||
|
||||
@@ -41,8 +41,8 @@ code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFj
|
||||
code.gitea.io/sdk/gitea v0.13.2 h1:wAnT/J7Z62q3fJXbgnecoaOBh8CM1Qq0/DakWxiv4yA=
|
||||
code.gitea.io/sdk/gitea v0.13.2/go.mod h1:lee2y8LeV3kQb2iK+hHlMqoadL4bp27QOkOV/hawLKg=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
gitea.com/go-chi/binding v0.0.0-20210113025129-03f1d313373c h1:NTtrGYjR40WUdkCdn26Y5LGFT52rIkFPkjmtgCAyiTs=
|
||||
gitea.com/go-chi/binding v0.0.0-20210113025129-03f1d313373c/go.mod h1:9bGA9dIsrz+wVQKH1DzvxuAvrudHaQ8Wx8hLme/GVGQ=
|
||||
gitea.com/go-chi/binding v0.0.0-20210301195521-1fe1c9a555e7 h1:xCVJPY823C8RWpgMabTw2kOglDrg0iS3GcQU6wdwHkU=
|
||||
gitea.com/go-chi/binding v0.0.0-20210301195521-1fe1c9a555e7/go.mod h1:AyfTrwtfYN54R/HmVvMYPnSTenH5bVoyh8x6tBluxEA=
|
||||
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e h1:zgPGaf3kXP0cVm9J0l8ZA2+XDzILYATg0CXbihR6N+o=
|
||||
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
|
||||
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e h1:YjaQU6XFicdhPN+MlGolcXO8seYY2+EY5g7vZPB17CQ=
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/models"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -190,6 +190,7 @@ func TestAPIEditUser(t *testing.T) {
|
||||
resp := session.MakeRequest(t, req, http.StatusUnprocessableEntity)
|
||||
|
||||
errMap := make(map[string]interface{})
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
json.Unmarshal(resp.Body.Bytes(), &errMap)
|
||||
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ package integrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -212,6 +212,8 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
|
||||
expected = ctx.ExpectedCode
|
||||
}
|
||||
resp := ctx.Session.MakeRequest(t, req, expected)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
pr := api.PullRequest{}
|
||||
err := decoder.Decode(&pr)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/routers/routes"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -62,6 +62,8 @@ func TestSessionFileCreation(t *testing.T) {
|
||||
}()
|
||||
|
||||
var config session.Options
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(oldSessionConfig), &config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -36,6 +35,7 @@ import (
|
||||
"code.gitea.io/gitea/routers/routes"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -376,6 +376,8 @@ func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string
|
||||
|
||||
func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
|
||||
t.Helper()
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonBytes, err := json.Marshal(v)
|
||||
assert.NoError(t, err)
|
||||
req := NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
|
||||
@@ -453,6 +455,8 @@ func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
|
||||
|
||||
func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
|
||||
t.Helper()
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
assert.NoError(t, decoder.Decode(v))
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ package integrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -70,6 +70,8 @@ func TestAccessTokenExchange(t *testing.T) {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
parsed := new(response)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
|
||||
assert.True(t, len(parsed.AccessToken) > 10)
|
||||
assert.True(t, len(parsed.RefreshToken) > 10)
|
||||
@@ -93,6 +95,8 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
parsed := new(response)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
|
||||
assert.True(t, len(parsed.AccessToken) > 10)
|
||||
assert.True(t, len(parsed.RefreshToken) > 10)
|
||||
@@ -181,6 +185,8 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
parsed := new(response)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
|
||||
assert.True(t, len(parsed.AccessToken) > 10)
|
||||
assert.True(t, len(parsed.RefreshToken) > 10)
|
||||
@@ -223,6 +229,8 @@ func TestRefreshTokenInvalidation(t *testing.T) {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
parsed := new(response)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
|
||||
|
||||
// test without invalidation
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -82,6 +82,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||
}
|
||||
|
||||
func testRepoCommitsWithStatus(t *testing.T, resp *httptest.ResponseRecorder, state string) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
statuses := []*api.CommitStatus{}
|
||||
assert.NoError(t, decoder.Decode(&statuses))
|
||||
|
||||
@@ -6,7 +6,6 @@ package integrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -158,6 +158,7 @@ func NewTestLogger() log.LoggerProvider {
|
||||
// Init inits connection writer with json config.
|
||||
// json config only need key "level".
|
||||
func (log *TestLogger) Init(config string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(config), log)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -8,7 +8,6 @@ package models
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -21,6 +20,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
@@ -655,6 +655,7 @@ func (c *Comment) LoadPushCommits() (err error) {
|
||||
|
||||
var data PushActionContent
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err = json.Unmarshal([]byte(c.Content), &data)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -1241,6 +1242,8 @@ func CreatePushPullComment(pusher *User, pr *PullRequest, oldCommitID, newCommit
|
||||
}
|
||||
|
||||
ops.Issue = pr.Issue
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dataJSON, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+11
-1
@@ -7,7 +7,6 @@ package models
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
@@ -75,11 +75,13 @@ type LDAPConfig struct {
|
||||
|
||||
// FromDB fills up a LDAPConfig from serialized format.
|
||||
func (cfg *LDAPConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a LDAPConfig to a serialized format.
|
||||
func (cfg *LDAPConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -101,11 +103,13 @@ type SMTPConfig struct {
|
||||
|
||||
// FromDB fills up an SMTPConfig from serialized format.
|
||||
func (cfg *SMTPConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, cfg)
|
||||
}
|
||||
|
||||
// ToDB exports an SMTPConfig to a serialized format.
|
||||
func (cfg *SMTPConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -116,11 +120,13 @@ type PAMConfig struct {
|
||||
|
||||
// FromDB fills up a PAMConfig from serialized format.
|
||||
func (cfg *PAMConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a PAMConfig to a serialized format.
|
||||
func (cfg *PAMConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -136,11 +142,13 @@ type OAuth2Config struct {
|
||||
|
||||
// FromDB fills up an OAuth2Config from serialized format.
|
||||
func (cfg *OAuth2Config) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, cfg)
|
||||
}
|
||||
|
||||
// ToDB exports an SMTPConfig to a serialized format.
|
||||
func (cfg *OAuth2Config) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -155,11 +163,13 @@ type SSPIConfig struct {
|
||||
|
||||
// FromDB fills up an SSPIConfig from serialized format.
|
||||
func (cfg *SSPIConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, cfg)
|
||||
}
|
||||
|
||||
// ToDB exports an SSPIConfig to a serialized format.
|
||||
func (cfg *SSPIConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@@ -72,6 +71,7 @@ func expandWebhooks(x *xorm.Engine) error {
|
||||
|
||||
for _, res := range results {
|
||||
var events HookEvent
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err = json.Unmarshal([]byte(res.Events), &events); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+11
-1
@@ -5,11 +5,11 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
)
|
||||
@@ -29,11 +29,13 @@ type UnitConfig struct {
|
||||
|
||||
// FromDB fills up a UnitConfig from serialized format.
|
||||
func (cfg *UnitConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a UnitConfig to a serialized format.
|
||||
func (cfg *UnitConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -44,11 +46,13 @@ type ExternalWikiConfig struct {
|
||||
|
||||
// FromDB fills up a ExternalWikiConfig from serialized format.
|
||||
func (cfg *ExternalWikiConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a ExternalWikiConfig to a serialized format.
|
||||
func (cfg *ExternalWikiConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -61,11 +65,13 @@ type ExternalTrackerConfig struct {
|
||||
|
||||
// FromDB fills up a ExternalTrackerConfig from serialized format.
|
||||
func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a ExternalTrackerConfig to a serialized format.
|
||||
func (cfg *ExternalTrackerConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -78,11 +84,13 @@ type IssuesConfig struct {
|
||||
|
||||
// FromDB fills up a IssuesConfig from serialized format.
|
||||
func (cfg *IssuesConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a IssuesConfig to a serialized format.
|
||||
func (cfg *IssuesConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
@@ -97,11 +105,13 @@ type PullRequestsConfig struct {
|
||||
|
||||
// FromDB fills up a PullRequestsConfig from serialized format.
|
||||
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Unmarshal(bs, &cfg)
|
||||
}
|
||||
|
||||
// ToDB exports a PullRequestsConfig to a serialized format.
|
||||
func (cfg *PullRequestsConfig) ToDB() ([]byte, error) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
return json.Marshal(cfg)
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -5,12 +5,12 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
migration "code.gitea.io/gitea/modules/migrations/base"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
@@ -105,6 +105,7 @@ func (task *Task) UpdateCols(cols ...string) error {
|
||||
func (task *Task) MigrateConfig() (*migration.MigrateOptions, error) {
|
||||
if task.Type == structs.TaskTypeMigrateRepo {
|
||||
var opts migration.MigrateOptions
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(task.PayloadContent), &opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -162,6 +163,7 @@ func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, e
|
||||
}
|
||||
|
||||
var opts migration.MigrateOptions
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal([]byte(task.PayloadContent), &opts); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -56,6 +56,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
||||
assert.Equal(t, tc.CountResult, len(heatmap), fmt.Sprintf("testcase %d", i))
|
||||
|
||||
//Test JSON rendering
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
jsonData, err := json.Marshal(heatmap)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.JSONResult, string(jsonData))
|
||||
|
||||
+6
-1
@@ -7,7 +7,6 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
gouuid "github.com/google/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// HookContentType is the content type of a web hook
|
||||
@@ -145,6 +145,8 @@ type Webhook struct {
|
||||
// AfterLoad updates the webhook object upon setting a column
|
||||
func (w *Webhook) AfterLoad() {
|
||||
w.HookEvent = &HookEvent{}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal([]byte(w.Events), w.HookEvent); err != nil {
|
||||
log.Error("Unmarshal[%d]: %v", w.ID, err)
|
||||
}
|
||||
@@ -157,6 +159,7 @@ func (w *Webhook) History(page int) ([]*HookTask, error) {
|
||||
|
||||
// UpdateEvent handles conversion from HookEvent to Events.
|
||||
func (w *Webhook) UpdateEvent() error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
data, err := json.Marshal(w.HookEvent)
|
||||
w.Events = string(data)
|
||||
return err
|
||||
@@ -689,6 +692,7 @@ func (t *HookTask) AfterLoad() {
|
||||
}
|
||||
|
||||
t.RequestInfo = &HookRequest{}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil {
|
||||
log.Error("Unmarshal RequestContent[%d]: %v", t.ID, err)
|
||||
}
|
||||
@@ -702,6 +706,7 @@ func (t *HookTask) AfterLoad() {
|
||||
}
|
||||
|
||||
func (t *HookTask) simpleMarshalJSON(v interface{}) string {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
p, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
log.Error("Marshal [%d]: %v", t.ID, err)
|
||||
|
||||
@@ -6,12 +6,12 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -58,6 +58,7 @@ func TestWebhook_UpdateEvent(t *testing.T) {
|
||||
assert.NoError(t, webhook.UpdateEvent())
|
||||
assert.NotEmpty(t, webhook.Events)
|
||||
actualHookEvent := &HookEvent{}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
assert.NoError(t, json.Unmarshal([]byte(webhook.Events), actualHookEvent))
|
||||
assert.Equal(t, *hookEvent, *actualHookEvent)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
@@ -34,6 +33,7 @@ import (
|
||||
"gitea.com/go-chi/cache"
|
||||
"gitea.com/go-chi/session"
|
||||
"github.com/go-chi/chi"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/unknwon/com"
|
||||
"github.com/unknwon/i18n"
|
||||
"github.com/unrolled/render"
|
||||
@@ -370,6 +370,7 @@ func (ctx *Context) Error(status int, contents ...string) {
|
||||
func (ctx *Context) JSON(status int, content interface{}) {
|
||||
ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
|
||||
ctx.Resp.WriteHeader(status)
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.NewEncoder(ctx.Resp).Encode(content); err != nil {
|
||||
ctx.ServerError("Render JSON failed", err)
|
||||
}
|
||||
|
||||
@@ -6,11 +6,12 @@ package eventsource
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func wrapNewlines(w io.Writer, prefix []byte, value []byte) (sum int64, err error) {
|
||||
@@ -79,6 +80,7 @@ func (e *Event) WriteTo(w io.Writer) (int64, error) {
|
||||
data = []byte(v)
|
||||
default:
|
||||
var err error
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
data, err = json.Marshal(e.Data)
|
||||
if err != nil {
|
||||
return sum, err
|
||||
|
||||
@@ -8,7 +8,6 @@ package httplib
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -23,6 +22,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
var defaultSetting = Settings{false, "GiteaServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false}
|
||||
@@ -434,6 +435,7 @@ func (r *Request) ToJSON(v interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err = json.Unmarshal(data, v)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package code
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/go-enry/go-enry/v2"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/olivere/elastic/v7"
|
||||
)
|
||||
|
||||
@@ -300,6 +300,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
|
||||
|
||||
repoID, fileName := parseIndexerID(hit.Id)
|
||||
var res = make(map[string]interface{})
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal(hit.Source, &res); err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package lfs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -15,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
//checkIsValidRequest check if it a valid request in case of bad request it write the response to ctx.
|
||||
@@ -184,6 +184,7 @@ func PostLockHandler(ctx *context.Context) {
|
||||
var req api.LFSLockRequest
|
||||
bodyReader := ctx.Req.Body
|
||||
defer bodyReader.Close()
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dec := json.NewDecoder(bodyReader)
|
||||
if err := dec.Decode(&req); err != nil {
|
||||
log.Warn("Failed to decode lock request as json. Error: %v", err)
|
||||
@@ -319,6 +320,7 @@ func UnLockHandler(ctx *context.Context) {
|
||||
var req api.LFSLockDeleteRequest
|
||||
bodyReader := ctx.Req.Body
|
||||
defer bodyReader.Close()
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dec := json.NewDecoder(bodyReader)
|
||||
if err := dec.Decode(&req); err != nil {
|
||||
log.Warn("Failed to decode lock request as json. Error: %v", err)
|
||||
|
||||
@@ -6,7 +6,6 @@ package lfs
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -23,6 +22,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -233,6 +233,7 @@ func getMetaHandler(ctx *context.Context) {
|
||||
ctx.Resp.Header().Set("Content-Type", metaMediaType)
|
||||
|
||||
if ctx.Req.Method == "GET" {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
enc := json.NewEncoder(ctx.Resp)
|
||||
if err := enc.Encode(Represent(rv, meta, true, false)); err != nil {
|
||||
log.Error("Failed to encode representation as json. Error: %v", err)
|
||||
@@ -304,6 +305,7 @@ func PostHandler(ctx *context.Context) {
|
||||
}
|
||||
ctx.Resp.WriteHeader(sentStatus)
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
enc := json.NewEncoder(ctx.Resp)
|
||||
if err := enc.Encode(Represent(rv, meta, meta.Existing, true)); err != nil {
|
||||
log.Error("Failed to encode representation as json. Error: %v", err)
|
||||
@@ -394,6 +396,7 @@ func BatchHandler(ctx *context.Context) {
|
||||
|
||||
respobj := &BatchResponse{Objects: responseObjects}
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
enc := json.NewEncoder(ctx.Resp)
|
||||
if err := enc.Encode(respobj); err != nil {
|
||||
log.Error("Failed to encode representation as json. Error: %v", err)
|
||||
@@ -531,6 +534,7 @@ func unpack(ctx *context.Context) *RequestVars {
|
||||
var p RequestVars
|
||||
bodyReader := r.Body
|
||||
defer bodyReader.Close()
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dec := json.NewDecoder(bodyReader)
|
||||
err := dec.Decode(&p)
|
||||
if err != nil {
|
||||
@@ -554,6 +558,7 @@ func unpackbatch(ctx *context.Context) *BatchVars {
|
||||
|
||||
bodyReader := r.Body
|
||||
defer bodyReader.Close()
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
dec := json.NewDecoder(bodyReader)
|
||||
err := dec.Decode(&bv)
|
||||
if err != nil {
|
||||
|
||||
+5
-2
@@ -6,9 +6,11 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type connWriter struct {
|
||||
@@ -104,9 +106,10 @@ func NewConn() LoggerProvider {
|
||||
// Init inits connection writer with json config.
|
||||
// json config only need key "level".
|
||||
func (log *ConnLogger) Init(jsonconfig string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(jsonconfig), log)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
}
|
||||
log.NewWriterLogger(&connWriter{
|
||||
ReconnectOnMsg: log.ReconnectOnMsg,
|
||||
|
||||
@@ -98,7 +98,8 @@ func TestConnLoggerBadConfig(t *testing.T) {
|
||||
logger := NewConn()
|
||||
|
||||
err := logger.Init("{")
|
||||
assert.Equal(t, "unexpected end of JSON input", err.Error())
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "Unable to parse JSON")
|
||||
logger.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// CanColorStdout reports if we can color the Stdout
|
||||
@@ -50,9 +52,10 @@ func NewConsoleLogger() LoggerProvider {
|
||||
// Init inits connection writer with json config.
|
||||
// json config only need key "level".
|
||||
func (log *ConsoleLogger) Init(config string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(config), log)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
}
|
||||
if log.Stderr {
|
||||
log.NewWriterLogger(&nopWriteCloser{
|
||||
|
||||
@@ -17,7 +17,8 @@ func TestConsoleLoggerBadConfig(t *testing.T) {
|
||||
logger := NewConsoleLogger()
|
||||
|
||||
err := logger.Init("{")
|
||||
assert.Equal(t, "unexpected end of JSON input", err.Error())
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "Unable to parse JSON")
|
||||
logger.Close()
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user