From 431a5ea43145cbadf76a6aaec69e81485e7efa27 Mon Sep 17 00:00:00 2001 From: bn4t Date: Sun, 11 Oct 2020 11:44:18 +0200 Subject: [PATCH] configure jsoniter to be compatible with encoding/json By default jsoniter sorts json keys non-reproducibly --- appservice/consumers/roomserver.go | 2 +- .../postgres/appservice_events_table.go | 4 ++-- .../storage/sqlite3/appservice_events_table.go | 4 ++-- appservice/workers/transaction_scheduler.go | 2 +- clientapi/auth/user_interactive.go | 10 +++++----- clientapi/httputil/httputil.go | 2 +- clientapi/jsonerror/jsonerror_test.go | 4 ++-- clientapi/producers/syncapi.go | 2 +- clientapi/routing/account_data.go | 2 +- clientapi/routing/createroom.go | 4 ++-- clientapi/routing/memberships.go | 2 +- clientapi/routing/register.go | 2 +- clientapi/routing/room_tagging.go | 4 ++-- clientapi/routing/state.go | 4 ++-- clientapi/threepid/invites.go | 2 +- cmd/dendrite-demo-libp2p/publicrooms.go | 4 ++-- cmd/dendrite-demo-yggdrasil/yggconn/node.go | 2 +- cmd/furl/main.go | 2 +- cmd/roomserver-integration-tests/main.go | 2 +- cmd/syncserver-integration-tests/main.go | 4 ++-- eduserver/api/wrapper.go | 2 +- eduserver/input/input.go | 4 ++-- federationapi/routing/devices.go | 2 +- federationapi/routing/invite.go | 4 ++-- federationapi/routing/keys.go | 8 ++++---- federationapi/routing/missingevents.go | 2 +- federationapi/routing/send.go | 10 +++++----- federationapi/routing/threepid.go | 6 +++--- federationsender/consumers/eduserver.go | 8 ++++---- federationsender/consumers/keychange.go | 4 ++-- federationsender/consumers/roomserver.go | 2 +- federationsender/queue/queue.go | 4 ++-- federationsender/storage/shared/storage.go | 2 +- .../storage/shared/storage_edus.go | 2 +- .../storage/shared/storage_pdus.go | 2 +- internal/httputil/http.go | 2 +- keyserver/internal/device_list_update.go | 2 +- keyserver/internal/internal.go | 4 ++-- keyserver/producers/keychange.go | 2 +- mediaapi/routing/download.go | 4 ++-- roomserver/acls/acls.go | 2 +- roomserver/api/api_trace.go | 2 +- roomserver/api/query.go | 8 ++++---- roomserver/auth/auth.go | 2 +- roomserver/internal/alias.go | 2 +- roomserver/internal/input/input.go | 2 +- roomserver/internal/perform/perform_peek.go | 2 +- roomserver/internal/query/query_test.go | 2 +- roomserver/roomserver_test.go | 2 +- roomserver/storage/shared/storage.go | 2 +- roomserver/storage/sqlite3/events_table.go | 2 +- roomserver/storage/sqlite3/rooms_table.go | 6 +++--- .../storage/sqlite3/state_snapshot_table.go | 4 ++-- syncapi/consumers/clientapi.go | 2 +- syncapi/consumers/eduserver_sendtodevice.go | 2 +- syncapi/consumers/eduserver_typing.go | 2 +- syncapi/consumers/keychange.go | 2 +- syncapi/consumers/roomserver.go | 2 +- syncapi/routing/filter.go | 2 +- .../postgres/current_room_state_table.go | 8 ++++---- syncapi/storage/postgres/filter_table.go | 4 ++-- syncapi/storage/postgres/invites_table.go | 4 ++-- .../postgres/output_room_events_table.go | 10 +++++----- .../storage/postgres/send_to_device_table.go | 2 +- syncapi/storage/shared/syncserver.go | 4 ++-- .../sqlite3/current_room_state_table.go | 8 ++++---- syncapi/storage/sqlite3/filter_table.go | 4 ++-- syncapi/storage/sqlite3/invites_table.go | 4 ++-- .../sqlite3/output_room_events_table.go | 18 +++++++++--------- .../storage/sqlite3/send_to_device_table.go | 2 +- syncapi/sync/notifier_test.go | 6 +++--- syncapi/sync/request.go | 2 +- syncapi/types/types.go | 4 ++-- syncapi/types/types_test.go | 2 +- 74 files changed, 136 insertions(+), 136 deletions(-) diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go index f8cb1364c..eed53c576 100644 --- a/appservice/consumers/roomserver.go +++ b/appservice/consumers/roomserver.go @@ -76,7 +76,7 @@ func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { // Parse out the event JSON var output api.OutputEvent - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("roomserver output log: message parse failure") return nil diff --git a/appservice/storage/postgres/appservice_events_table.go b/appservice/storage/postgres/appservice_events_table.go index 3a2c4db98..d02daac32 100644 --- a/appservice/storage/postgres/appservice_events_table.go +++ b/appservice/storage/postgres/appservice_events_table.go @@ -162,7 +162,7 @@ func retrieveEvents(eventRows *sql.Rows, limit int) (events []gomatrixserverlib. } // Unmarshal eventJSON - if err = json.Unmarshal(eventJSON, &event); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventJSON, &event); err != nil { return nil, 0, 0, false, err } @@ -220,7 +220,7 @@ func (s *eventsStatements) insertEvent( event *gomatrixserverlib.HeaderedEvent, ) (err error) { // Convert event to JSON before inserting - eventJSON, err := json.Marshal(event) + eventJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } diff --git a/appservice/storage/sqlite3/appservice_events_table.go b/appservice/storage/sqlite3/appservice_events_table.go index a88432a40..b5ca3f8e2 100644 --- a/appservice/storage/sqlite3/appservice_events_table.go +++ b/appservice/storage/sqlite3/appservice_events_table.go @@ -167,7 +167,7 @@ func retrieveEvents(eventRows *sql.Rows, limit int) (events []gomatrixserverlib. } // Unmarshal eventJSON - if err = json.Unmarshal(eventJSON, &event); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventJSON, &event); err != nil { return nil, 0, 0, false, err } @@ -225,7 +225,7 @@ func (s *eventsStatements) insertEvent( event *gomatrixserverlib.HeaderedEvent, ) (err error) { // Convert event to JSON before inserting - eventJSON, err := json.Marshal(event) + eventJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } diff --git a/appservice/workers/transaction_scheduler.go b/appservice/workers/transaction_scheduler.go index e93ece5e8..b65cdfed1 100644 --- a/appservice/workers/transaction_scheduler.go +++ b/appservice/workers/transaction_scheduler.go @@ -196,7 +196,7 @@ func createTransaction( Events: ev, } - transactionJSON, err = json.Marshal(transaction) + transactionJSON, err = json.ConfigCompatibleWithStandardLibrary.Marshal(transaction) if err != nil { return } diff --git a/clientapi/auth/user_interactive.go b/clientapi/auth/user_interactive.go index c94ed764b..89f20ab9d 100644 --- a/clientapi/auth/user_interactive.go +++ b/clientapi/auth/user_interactive.go @@ -182,19 +182,19 @@ func (u *UserInteractive) NewSession() *util.JSONResponse { // standard challenge response. func (u *UserInteractive) ResponseWithChallenge(sessionID string, response interface{}) *util.JSONResponse { mixedObjects := make(map[string]interface{}) - b, err := json.Marshal(response) + b, err := json.ConfigCompatibleWithStandardLibrary.Marshal(response) if err != nil { ise := jsonerror.InternalServerError() return &ise } - _ = json.Unmarshal(b, &mixedObjects) + _ = json.ConfigCompatibleWithStandardLibrary.Unmarshal(b, &mixedObjects) challenge := u.Challenge(sessionID) - b, err = json.Marshal(challenge.JSON) + b, err = json.ConfigCompatibleWithStandardLibrary.Marshal(challenge.JSON) if err != nil { ise := jsonerror.InternalServerError() return &ise } - _ = json.Unmarshal(b, &mixedObjects) + _ = json.ConfigCompatibleWithStandardLibrary.Unmarshal(b, &mixedObjects) return &util.JSONResponse{ Code: 401, @@ -238,7 +238,7 @@ func (u *UserInteractive) Verify(ctx context.Context, bodyBytes []byte, device * } r := loginType.Request() - if err := json.Unmarshal([]byte(gjson.GetBytes(bodyBytes, "auth").Raw), r); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(gjson.GetBytes(bodyBytes, "auth").Raw), r); err != nil { return nil, &util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()), diff --git a/clientapi/httputil/httputil.go b/clientapi/httputil/httputil.go index 4be8202c4..579a89846 100644 --- a/clientapi/httputil/httputil.go +++ b/clientapi/httputil/httputil.go @@ -44,7 +44,7 @@ func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONRespon } } - if err := json.Unmarshal(body, iface); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(body, iface); err != nil { // TODO: We may want to suppress the Error() return in production? It's useful when // debugging because an error will be produced for both invalid/malformed JSON AND // valid JSON with incorrect types for values. diff --git a/clientapi/jsonerror/jsonerror_test.go b/clientapi/jsonerror/jsonerror_test.go index 697de5584..568cf93eb 100644 --- a/clientapi/jsonerror/jsonerror_test.go +++ b/clientapi/jsonerror/jsonerror_test.go @@ -22,7 +22,7 @@ import ( func TestLimitExceeded(t *testing.T) { e := LimitExceeded("too fast", 5000) - jsonBytes, err := json.Marshal(&e) + jsonBytes, err := json.ConfigCompatibleWithStandardLibrary.Marshal(&e) if err != nil { t.Fatalf("TestLimitExceeded: Failed to marshal LimitExceeded error. %s", err.Error()) } @@ -34,7 +34,7 @@ func TestLimitExceeded(t *testing.T) { func TestForbidden(t *testing.T) { e := Forbidden("you shall not pass") - jsonBytes, err := json.Marshal(&e) + jsonBytes, err := json.ConfigCompatibleWithStandardLibrary.Marshal(&e) if err != nil { t.Fatalf("TestForbidden: Failed to marshal Forbidden error. %s", err.Error()) } diff --git a/clientapi/producers/syncapi.go b/clientapi/producers/syncapi.go index 2a5b95b06..2145ba3b9 100644 --- a/clientapi/producers/syncapi.go +++ b/clientapi/producers/syncapi.go @@ -36,7 +36,7 @@ func (p *SyncAPIProducer) SendData(userID string, roomID string, dataType string RoomID: roomID, Type: dataType, } - value, err := json.Marshal(data) + value, err := json.ConfigCompatibleWithStandardLibrary.Marshal(data) if err != nil { return err } diff --git a/clientapi/routing/account_data.go b/clientapi/routing/account_data.go index 60f235d19..7109176a1 100644 --- a/clientapi/routing/account_data.go +++ b/clientapi/routing/account_data.go @@ -171,7 +171,7 @@ func SaveReadMarker( } } - data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead}) + data, err := json.ConfigCompatibleWithStandardLibrary.Marshal(fullyReadEvent{EventID: r.FullyRead}) if err != nil { return jsonerror.InternalServerError() } diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index 97cd2b93e..6862bcb1d 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -100,7 +100,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse { // creation_content map into bytes and then unmarshalling the bytes into // eventutil.CreateContent. - creationContentBytes, err := json.Marshal(r.CreationContent) + creationContentBytes, err := json.ConfigCompatibleWithStandardLibrary.Marshal(r.CreationContent) if err != nil { return &util.JSONResponse{ Code: http.StatusBadRequest, @@ -109,7 +109,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse { } var CreationContent gomatrixserverlib.CreateContent - err = json.Unmarshal(creationContentBytes, &CreationContent) + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(creationContentBytes, &CreationContent) if err != nil { return &util.JSONResponse{ Code: http.StatusBadRequest, diff --git a/clientapi/routing/memberships.go b/clientapi/routing/memberships.go index 7981812d6..5225b4497 100644 --- a/clientapi/routing/memberships.go +++ b/clientapi/routing/memberships.go @@ -74,7 +74,7 @@ func GetMemberships( res.Joined = make(map[string]joinedMember) for _, ev := range queryRes.JoinEvents { var content joinedMember - if err := json.Unmarshal(ev.Content, &content); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(ev.Content, &content); err != nil { util.GetLogger(req.Context()).WithError(err).Error("failed to unmarshal event content") return jsonerror.InternalServerError() } diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index ad02ba2a0..66d83c85b 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -302,7 +302,7 @@ func validateRecaptcha( JSON: jsonerror.Unknown("Error in contacting captcha server" + err.Error()), } } - err = json.Unmarshal(body, &r) + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(body, &r) if err != nil { return &util.JSONResponse{ Code: http.StatusInternalServerError, diff --git a/clientapi/routing/room_tagging.go b/clientapi/routing/room_tagging.go index 905f4d0a4..c91abf48a 100644 --- a/clientapi/routing/room_tagging.go +++ b/clientapi/routing/room_tagging.go @@ -184,7 +184,7 @@ func obtainSavedTags( if !ok { return } - if err = json.Unmarshal(data, &tags); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &tags); err != nil { return } return tags, nil @@ -198,7 +198,7 @@ func saveTagData( userAPI api.UserInternalAPI, Tag gomatrix.TagContent, ) error { - newTagData, err := json.Marshal(Tag) + newTagData, err := json.ConfigCompatibleWithStandardLibrary.Marshal(Tag) if err != nil { return err } diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go index c2f622048..df5177567 100644 --- a/clientapi/routing/state.go +++ b/clientapi/routing/state.go @@ -64,7 +64,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a for _, ev := range stateRes.StateEvents { if ev.Type() == gomatrixserverlib.MRoomHistoryVisibility { content := map[string]string{} - if err := json.Unmarshal(ev.Content(), &content); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(ev.Content(), &content); err != nil { util.GetLogger(ctx).WithError(err).Error("json.Unmarshal for history visibility failed") return jsonerror.InternalServerError() } @@ -205,7 +205,7 @@ func OnIncomingStateTypeRequest( for _, ev := range stateRes.StateEvents { if ev.Type() == gomatrixserverlib.MRoomHistoryVisibility { content := map[string]string{} - if err := json.Unmarshal(ev.Content(), &content); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(ev.Content(), &content); err != nil { util.GetLogger(ctx).WithError(err).Error("json.Unmarshal for history visibility failed") return jsonerror.InternalServerError() } diff --git a/clientapi/threepid/invites.go b/clientapi/threepid/invites.go index 0c1c02d72..3c48e197d 100644 --- a/clientapi/threepid/invites.go +++ b/clientapi/threepid/invites.go @@ -303,7 +303,7 @@ func checkIDServerSignatures( ctx context.Context, body *MembershipRequest, res *idServerLookupResponse, ) error { // Mashall the body so we can give it to VerifyJSON - marshalledBody, err := json.Marshal(*res) + marshalledBody, err := json.ConfigCompatibleWithStandardLibrary.Marshal(*res) if err != nil { return err } diff --git a/cmd/dendrite-demo-libp2p/publicrooms.go b/cmd/dendrite-demo-libp2p/publicrooms.go index d3b333409..55fae679c 100644 --- a/cmd/dendrite-demo-libp2p/publicrooms.go +++ b/cmd/dendrite-demo-libp2p/publicrooms.go @@ -111,7 +111,7 @@ func (p *publicRoomsProvider) AdvertiseRooms() error { } advertised := 0 for _, room := range ourRooms { - if j, err := json.Marshal(room); err == nil { + if j, err := json.ConfigCompatibleWithStandardLibrary.Marshal(room); err == nil { if err := p.topic.Publish(context.TODO(), j); err != nil { fmt.Println("Failed to publish public room:", err) } else { @@ -133,7 +133,7 @@ func (p *publicRoomsProvider) FindRooms() { received := discoveredRoom{ time: time.Now(), } - if err := json.Unmarshal(msg.Data, &received.room); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Data, &received.room); err != nil { fmt.Println("Unmarshal error:", err) continue } diff --git a/cmd/dendrite-demo-yggdrasil/yggconn/node.go b/cmd/dendrite-demo-yggdrasil/yggconn/node.go index c808e5242..ef720e64a 100644 --- a/cmd/dendrite-demo-yggdrasil/yggconn/node.go +++ b/cmd/dendrite-demo-yggdrasil/yggconn/node.go @@ -90,7 +90,7 @@ func Setup(instanceName, storageDirectory string) (*Node, error) { if e != nil { panic(err) } - if err := json.Unmarshal([]byte(yggconf), &n.config); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(yggconf), &n.config); err != nil { panic(err) } } diff --git a/cmd/furl/main.go b/cmd/furl/main.go index 2df6458d5..162d8fd18 100644 --- a/cmd/furl/main.go +++ b/cmd/furl/main.go @@ -76,7 +76,7 @@ func main() { bodyBytes = append(bodyBytes, bytes...) } fmt.Println("Done!") - if err = json.Unmarshal(bodyBytes, &bodyObj); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(bodyBytes, &bodyObj); err != nil { panic(err) } } diff --git a/cmd/roomserver-integration-tests/main.go b/cmd/roomserver-integration-tests/main.go index a59a9a4c6..08f63b953 100644 --- a/cmd/roomserver-integration-tests/main.go +++ b/cmd/roomserver-integration-tests/main.go @@ -207,7 +207,7 @@ func writeToRoomServer(input []string, roomserverURL string) error { var err error request.InputRoomEvents = make([]api.InputRoomEvent, len(input)) for i := range input { - if err = json.Unmarshal([]byte(input[i]), &request.InputRoomEvents[i]); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(input[i]), &request.InputRoomEvents[i]); err != nil { return err } } diff --git a/cmd/syncserver-integration-tests/main.go b/cmd/syncserver-integration-tests/main.go index dd3bafdfa..d716af720 100644 --- a/cmd/syncserver-integration-tests/main.go +++ b/cmd/syncserver-integration-tests/main.go @@ -101,13 +101,13 @@ func createTestUser(database, username, token string) error { // Panics if there are any problems. func clientEventJSONForOutputRoomEvent(outputRoomEvent string) string { var out api.OutputEvent - if err := json.Unmarshal([]byte(outputRoomEvent), &out); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(outputRoomEvent), &out); err != nil { panic("failed to unmarshal output room event: " + err.Error()) } clientEvs := gomatrixserverlib.ToClientEvents([]gomatrixserverlib.Event{ out.NewRoomEvent.Event.Event, }, gomatrixserverlib.FormatSync) - b, err := json.Marshal(clientEvs[0]) + b, err := json.ConfigCompatibleWithStandardLibrary.Marshal(clientEvs[0]) if err != nil { panic("failed to marshal client event as json: " + err.Error()) } diff --git a/eduserver/api/wrapper.go b/eduserver/api/wrapper.go index fcaf1580b..e15b3bde7 100644 --- a/eduserver/api/wrapper.go +++ b/eduserver/api/wrapper.go @@ -49,7 +49,7 @@ func SendToDevice( ctx context.Context, eduAPI EDUServerInputAPI, sender, userID, deviceID, eventType string, message interface{}, ) error { - js, err := json.Marshal(message) + js, err := json.ConfigCompatibleWithStandardLibrary.Marshal(message) if err != nil { return err } diff --git a/eduserver/input/input.go b/eduserver/input/input.go index 723166348..7f96d1145 100644 --- a/eduserver/input/input.go +++ b/eduserver/input/input.go @@ -94,7 +94,7 @@ func (t *EDUServerInputAPI) sendTypingEvent(ite *api.InputTypingEvent) error { ote.ExpireTime = &expireTime } - eventJSON, err := json.Marshal(ote) + eventJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(ote) if err != nil { return err } @@ -153,7 +153,7 @@ func (t *EDUServerInputAPI) sendToDeviceEvent(ise *api.InputSendToDeviceEvent) e SendToDeviceEvent: ise.SendToDeviceEvent, } - eventJSON, err := json.Marshal(ote) + eventJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(ote) if err != nil { logrus.WithError(err).Error("sendToDevice failed json.Marshal") return err diff --git a/federationapi/routing/devices.go b/federationapi/routing/devices.go index 601125125..7b5d5c363 100644 --- a/federationapi/routing/devices.go +++ b/federationapi/routing/devices.go @@ -46,7 +46,7 @@ func GetUserDevices( for _, dev := range res.Devices { var key gomatrixserverlib.RespUserDeviceKeys - err := json.Unmarshal(dev.DeviceKeys.KeyJSON, &key) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(dev.DeviceKeys.KeyJSON, &key) if err != nil { util.GetLogger(req.Context()).WithError(err).Warnf("malformed device key: %s", string(dev.DeviceKeys.KeyJSON)) continue diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 3bc042024..f1ee8e0a7 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -40,7 +40,7 @@ func InviteV2( keys gomatrixserverlib.JSONVerifier, ) util.JSONResponse { inviteReq := gomatrixserverlib.InviteV2Request{} - err := json.Unmarshal(request.Content(), &inviteReq) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &inviteReq) switch err.(type) { case gomatrixserverlib.BadJSONError: return util.JSONResponse{ @@ -86,7 +86,7 @@ func InviteV1( } } var strippedState []gomatrixserverlib.InviteV2StrippedState - if err := json.Unmarshal(event.Unsigned(), &strippedState); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Unsigned(), &strippedState); err != nil { // just warn, they may not have added any. util.GetLogger(httpReq.Context()).Warnf("failed to extract stripped state from invite event") } diff --git a/federationapi/routing/keys.go b/federationapi/routing/keys.go index cc9e8768c..4c9374335 100644 --- a/federationapi/routing/keys.go +++ b/federationapi/routing/keys.go @@ -41,7 +41,7 @@ func QueryDeviceKeys( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, keyAPI api.KeyInternalAPI, thisServer gomatrixserverlib.ServerName, ) util.JSONResponse { var qkr queryKeysRequest - err := json.Unmarshal(request.Content(), &qkr) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &qkr) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, @@ -87,7 +87,7 @@ func ClaimOneTimeKeys( httpReq *http.Request, request *gomatrixserverlib.FederationRequest, keyAPI api.KeyInternalAPI, thisServer gomatrixserverlib.ServerName, ) util.JSONResponse { var cor claimOTKsRequest - err := json.Unmarshal(request.Content(), &cor) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &cor) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, @@ -157,7 +157,7 @@ func localKeys(cfg *config.FederationAPI, validUntil time.Time) (*gomatrixserver } } - toSign, err := json.Marshal(keys.ServerKeyFields) + toSign, err := json.ConfigCompatibleWithStandardLibrary.Marshal(keys.ServerKeyFields) if err != nil { return nil, err } @@ -208,7 +208,7 @@ func NotaryKeys( continue } - j, err := json.Marshal(keys) + j, err := json.ConfigCompatibleWithStandardLibrary.Marshal(keys) if err != nil { logrus.WithError(err).Errorf("Failed to marshal %q response", serverName) return jsonerror.InternalServerError() diff --git a/federationapi/routing/missingevents.go b/federationapi/routing/missingevents.go index 631868a26..e8c903feb 100644 --- a/federationapi/routing/missingevents.go +++ b/federationapi/routing/missingevents.go @@ -39,7 +39,7 @@ func GetMissingEvents( roomID string, ) util.JSONResponse { var gme getMissingEventRequest - if err := json.Unmarshal(request.Content(), &gme); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &gme); err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index ec7d5048f..b1e021ffa 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -61,7 +61,7 @@ func Send( EDUs []gomatrixserverlib.EDU `json:"edus"` } - if err := json.Unmarshal(request.Content(), &txnEvents); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &txnEvents); err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), @@ -134,7 +134,7 @@ func (t *txnReq) processTransaction(ctx context.Context) (*gomatrixserverlib.Res var header struct { RoomID string `json:"room_id"` } - if err := json.Unmarshal(pdu, &header); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(pdu, &header); err != nil { util.GetLogger(ctx).WithError(err).Warn("Transaction: Failed to extract room ID from event") // We don't know the event ID at this point so we can't return the // failure in the PDU results @@ -290,7 +290,7 @@ func (t *txnReq) processEDUs(ctx context.Context) { UserID string `json:"user_id"` Typing bool `json:"typing"` } - if err := json.Unmarshal(e.Content, &typingPayload); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(e.Content, &typingPayload); err != nil { util.GetLogger(ctx).WithError(err).Error("Failed to unmarshal typing event") continue } @@ -300,7 +300,7 @@ func (t *txnReq) processEDUs(ctx context.Context) { case gomatrixserverlib.MDirectToDevice: // https://matrix.org/docs/spec/server_server/r0.1.3#m-direct-to-device-schema var directPayload gomatrixserverlib.ToDeviceMessage - if err := json.Unmarshal(e.Content, &directPayload); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(e.Content, &directPayload); err != nil { util.GetLogger(ctx).WithError(err).Error("Failed to unmarshal send-to-device events") continue } @@ -326,7 +326,7 @@ func (t *txnReq) processEDUs(ctx context.Context) { func (t *txnReq) processDeviceListUpdate(ctx context.Context, e gomatrixserverlib.EDU) { var payload gomatrixserverlib.DeviceListUpdateEvent - if err := json.Unmarshal(e.Content, &payload); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(e.Content, &payload); err != nil { util.GetLogger(ctx).WithError(err).Error("Failed to unmarshal device list update event") return } diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index f3b0fd17e..4c6c58168 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -111,7 +111,7 @@ func ExchangeThirdPartyInvite( federation *gomatrixserverlib.FederationClient, ) util.JSONResponse { var builder gomatrixserverlib.EventBuilder - if err := json.Unmarshal(request.Content(), &builder); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(request.Content(), &builder); err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()), @@ -368,7 +368,7 @@ func fillDisplayName( builder *gomatrixserverlib.EventBuilder, authEvents gomatrixserverlib.AuthEvents, ) error { var content gomatrixserverlib.MemberContent - if err := json.Unmarshal(builder.Content, &content); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(builder.Content, &content); err != nil { return err } @@ -381,7 +381,7 @@ func fillDisplayName( } var thirdPartyInviteContent gomatrixserverlib.ThirdPartyInviteContent - if err := json.Unmarshal(thirdPartyInviteEvent.Content(), &thirdPartyInviteContent); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(thirdPartyInviteEvent.Content(), &thirdPartyInviteContent); err != nil { return err } diff --git a/federationsender/consumers/eduserver.go b/federationsender/consumers/eduserver.go index 82f99df16..5ee735491 100644 --- a/federationsender/consumers/eduserver.go +++ b/federationsender/consumers/eduserver.go @@ -90,7 +90,7 @@ func (t *OutputEDUConsumer) Start() error { func (t *OutputEDUConsumer) onSendToDeviceEvent(msg *sarama.ConsumerMessage) error { // Extract the send-to-device event from msg. var ote api.OutputSendToDeviceEvent - if err := json.Unmarshal(msg.Value, &ote); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &ote); err != nil { log.WithError(err).Errorf("eduserver output log: message parse failed (expected send-to-device)") return nil } @@ -127,7 +127,7 @@ func (t *OutputEDUConsumer) onSendToDeviceEvent(msg *sarama.ConsumerMessage) err }, }, } - if edu.Content, err = json.Marshal(tdm); err != nil { + if edu.Content, err = json.ConfigCompatibleWithStandardLibrary.Marshal(tdm); err != nil { return err } @@ -140,7 +140,7 @@ func (t *OutputEDUConsumer) onSendToDeviceEvent(msg *sarama.ConsumerMessage) err func (t *OutputEDUConsumer) onTypingEvent(msg *sarama.ConsumerMessage) error { // Extract the typing event from msg. var ote api.OutputTypingEvent - if err := json.Unmarshal(msg.Value, &ote); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &ote); err != nil { // Skip this msg but continue processing messages. log.WithError(err).Errorf("eduserver output log: message parse failed (expected typing)") return nil @@ -168,7 +168,7 @@ func (t *OutputEDUConsumer) onTypingEvent(msg *sarama.ConsumerMessage) error { } edu := &gomatrixserverlib.EDU{Type: ote.Event.Type} - if edu.Content, err = json.Marshal(map[string]interface{}{ + if edu.Content, err = json.ConfigCompatibleWithStandardLibrary.Marshal(map[string]interface{}{ "room_id": ote.Event.RoomID, "user_id": ote.Event.UserID, "typing": ote.Event.Typing, diff --git a/federationsender/consumers/keychange.go b/federationsender/consumers/keychange.go index ae1bef601..a1c2ca15c 100644 --- a/federationsender/consumers/keychange.go +++ b/federationsender/consumers/keychange.go @@ -77,7 +77,7 @@ func (t *KeyChangeConsumer) Start() error { // key change events topic from the key server. func (t *KeyChangeConsumer) onMessage(msg *sarama.ConsumerMessage) error { var m api.DeviceMessage - if err := json.Unmarshal(msg.Value, &m); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &m); err != nil { log.WithError(err).Errorf("failed to read device message from key change topic") return nil } @@ -123,7 +123,7 @@ func (t *KeyChangeConsumer) onMessage(msg *sarama.ConsumerMessage) error { Deleted: len(m.KeyJSON) == 0, Keys: m.KeyJSON, } - if edu.Content, err = json.Marshal(event); err != nil { + if edu.Content, err = json.ConfigCompatibleWithStandardLibrary.Marshal(event); err != nil { return err } diff --git a/federationsender/consumers/roomserver.go b/federationsender/consumers/roomserver.go index 5d9b2707d..60cd732dd 100644 --- a/federationsender/consumers/roomserver.go +++ b/federationsender/consumers/roomserver.go @@ -78,7 +78,7 @@ func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { // Parse out the event JSON var output api.OutputEvent - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("roomserver output log: message parse failure") return nil diff --git a/federationsender/queue/queue.go b/federationsender/queue/queue.go index 907c80091..c4cf8145b 100644 --- a/federationsender/queue/queue.go +++ b/federationsender/queue/queue.go @@ -160,7 +160,7 @@ func (oqs *OutgoingQueues) SendEvent( "destinations": len(destmap), "event": ev.EventID(), }).Infof("Sending event") - headeredJSON, err := json.Marshal(ev) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(ev) if err != nil { return fmt.Errorf("json.Marshal: %w", err) } @@ -225,7 +225,7 @@ func (oqs *OutgoingQueues) SendEDU( "destinations": len(destmap), "edu_type": e.Type, }).Info("Sending EDU event") - ephemeralJSON, err := json.Marshal(e) + ephemeralJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(e) if err != nil { return fmt.Errorf("json.Marshal: %w", err) } diff --git a/federationsender/storage/shared/storage.go b/federationsender/storage/shared/storage.go index abe670a7d..3cfb212f8 100644 --- a/federationsender/storage/shared/storage.go +++ b/federationsender/storage/shared/storage.go @@ -51,7 +51,7 @@ func (e *Receipt) Empty() bool { } func (e *Receipt) String() string { - j, _ := json.Marshal(e.nids) + j, _ := json.ConfigCompatibleWithStandardLibrary.Marshal(e.nids) return string(j) } diff --git a/federationsender/storage/shared/storage_edus.go b/federationsender/storage/shared/storage_edus.go index 31fe6c12d..da626719b 100644 --- a/federationsender/storage/shared/storage_edus.go +++ b/federationsender/storage/shared/storage_edus.go @@ -77,7 +77,7 @@ func (d *Database) GetNextTransactionEDUs( for _, blob := range blobs { var event gomatrixserverlib.EDU - if err := json.Unmarshal(blob, &event); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(blob, &event); err != nil { return fmt.Errorf("json.Unmarshal: %w", err) } edus = append(edus, &event) diff --git a/federationsender/storage/shared/storage_pdus.go b/federationsender/storage/shared/storage_pdus.go index dd7111e96..024ad5461 100644 --- a/federationsender/storage/shared/storage_pdus.go +++ b/federationsender/storage/shared/storage_pdus.go @@ -93,7 +93,7 @@ func (d *Database) GetNextTransactionPDUs( for _, blob := range blobs { var event gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(blob, &event); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(blob, &event); err != nil { return fmt.Errorf("json.Unmarshal: %w", err) } events = append(events, &event) diff --git a/internal/httputil/http.go b/internal/httputil/http.go index 436edd06c..bda07bcb0 100644 --- a/internal/httputil/http.go +++ b/internal/httputil/http.go @@ -33,7 +33,7 @@ func PostJSON( ctx context.Context, span opentracing.Span, httpClient *http.Client, apiURL string, request, response interface{}, ) error { - jsonBytes, err := json.Marshal(request) + jsonBytes, err := json.ConfigCompatibleWithStandardLibrary.Marshal(request) if err != nil { return err } diff --git a/keyserver/internal/device_list_update.go b/keyserver/internal/device_list_update.go index 4b85534c2..fa5cc6ae8 100644 --- a/keyserver/internal/device_list_update.go +++ b/keyserver/internal/device_list_update.go @@ -370,7 +370,7 @@ func (u *DeviceListUpdater) updateDeviceList(res *gomatrixserverlib.RespUserDevi keys := make([]api.DeviceMessage, len(res.Devices)) existingKeys := make([]api.DeviceMessage, len(res.Devices)) for i, device := range res.Devices { - keyJSON, err := json.Marshal(device.Keys) + keyJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(device.Keys) if err != nil { util.GetLogger(ctx).WithField("keys", device.Keys).Error("failed to marshal keys, skipping device") continue diff --git a/keyserver/internal/internal.go b/keyserver/internal/internal.go index 2cf39a40a..8d050bdbe 100644 --- a/keyserver/internal/internal.go +++ b/keyserver/internal/internal.go @@ -170,7 +170,7 @@ func (a *KeyInternalAPI) claimRemoteKeys( for deviceID, nest2 := range nest { res.OneTimeKeys[userID][deviceID] = make(map[string]json.RawMessage) for keyIDWithAlgo, otk := range nest2 { - keyJSON, err := json.Marshal(otk) + keyJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(otk) if err != nil { continue } @@ -338,7 +338,7 @@ func (a *KeyInternalAPI) queryRemoteKeys( for userID, nest := range result.DeviceKeys { res.DeviceKeys[userID] = make(map[string]json.RawMessage) for deviceID, deviceKey := range nest { - keyJSON, err := json.Marshal(deviceKey) + keyJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(deviceKey) if err != nil { continue } diff --git a/keyserver/producers/keychange.go b/keyserver/producers/keychange.go index c67b94450..f032110c7 100644 --- a/keyserver/producers/keychange.go +++ b/keyserver/producers/keychange.go @@ -47,7 +47,7 @@ func (p *KeyChange) ProduceKeyChanges(keys []api.DeviceMessage) error { for _, key := range keys { var m sarama.ProducerMessage - value, err := json.Marshal(key) + value, err := json.ConfigCompatibleWithStandardLibrary.Marshal(key) if err != nil { return err } diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index 3b2f1d392..b46f6243d 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -147,12 +147,12 @@ func Download( func (r *downloadRequest) jsonErrorResponse(w http.ResponseWriter, res util.JSONResponse) { // Marshal JSON response into raw bytes to send as the HTTP body - resBytes, err := json.Marshal(res.JSON) + resBytes, err := json.ConfigCompatibleWithStandardLibrary.Marshal(res.JSON) if err != nil { r.Logger.WithError(err).Error("Failed to marshal JSONResponse") // this should never fail to be marshalled so drop err to the floor res = util.MessageResponse(http.StatusNotFound, "Download request failed: "+err.Error()) - resBytes, _ = json.Marshal(res.JSON) + resBytes, _ = json.ConfigCompatibleWithStandardLibrary.Marshal(res.JSON) } // Set status code and write the body diff --git a/roomserver/acls/acls.go b/roomserver/acls/acls.go index 1659c6ca1..e16b540b5 100644 --- a/roomserver/acls/acls.go +++ b/roomserver/acls/acls.go @@ -89,7 +89,7 @@ func compileACLRegex(orig string) (*regexp.Regexp, error) { func (s *ServerACLs) OnServerACLUpdate(state *gomatrixserverlib.Event) { acls := &serverACL{} - if err := json.Unmarshal(state.Content(), &acls.ServerACL); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(state.Content(), &acls.ServerACL); err != nil { logrus.WithError(err).Errorf("Failed to unmarshal state content for server ACLs") return } diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go index d5c292f63..1d52333ed 100644 --- a/roomserver/api/api_trace.go +++ b/roomserver/api/api_trace.go @@ -307,7 +307,7 @@ func (t *RoomserverInternalAPITrace) QueryServerBannedFromRoom(ctx context.Conte } func js(thing interface{}) string { - b, err := json.Marshal(thing) + b, err := json.ConfigCompatibleWithStandardLibrary.Marshal(thing) if err != nil { return fmt.Sprintf("Marshal error:%s", err) } diff --git a/roomserver/api/query.go b/roomserver/api/query.go index 08c42b62c..abee12842 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -352,12 +352,12 @@ func (r *QueryBulkStateContentResponse) MarshalJSON() ([]byte, error) { se[fmt.Sprintf("%s\x1F%s\x1F%s", roomID, tuple.EventType, tuple.StateKey)] = event } } - return json.Marshal(se) + return json.ConfigCompatibleWithStandardLibrary.Marshal(se) } func (r *QueryBulkStateContentResponse) UnmarshalJSON(data []byte) error { wireFormat := make(map[string]string) - err := json.Unmarshal(data, &wireFormat) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &wireFormat) if err != nil { return err } @@ -383,12 +383,12 @@ func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) { // use 0x1F (unit separator) as the delimiter between type/state key, se[fmt.Sprintf("%s\x1F%s", k.EventType, k.StateKey)] = v } - return json.Marshal(se) + return json.ConfigCompatibleWithStandardLibrary.Marshal(se) } func (r *QueryCurrentStateResponse) UnmarshalJSON(data []byte) error { res := make(map[string]*gomatrixserverlib.HeaderedEvent) - err := json.Unmarshal(data, &res) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(data, &res) if err != nil { return err } diff --git a/roomserver/auth/auth.go b/roomserver/auth/auth.go index 560a18c08..cc94a8537 100644 --- a/roomserver/auth/auth.go +++ b/roomserver/auth/auth.go @@ -65,7 +65,7 @@ func HistoryVisibilityForRoom(authEvents []gomatrixserverlib.Event) string { content := struct { HistoryVisibility string `json:"history_visibility"` }{} - if err := json.Unmarshal(ev.Content(), &content); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(ev.Content(), &content); err != nil { break // value is not understood } for _, s := range knownStates { diff --git a/roomserver/internal/alias.go b/roomserver/internal/alias.go index 9092ed03b..0c9f28376 100644 --- a/roomserver/internal/alias.go +++ b/roomserver/internal/alias.go @@ -199,7 +199,7 @@ func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent( return err } content := roomAliasesContent{Aliases: aliases} - rawContent, err := json.Marshal(content) + rawContent, err := json.ConfigCompatibleWithStandardLibrary.Marshal(content) if err != nil { return err } diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index 80e4554b0..eabf4a6f1 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -74,7 +74,7 @@ func (w *inputWorker) start() { func (r *Inputer) WriteOutputEvents(roomID string, updates []api.OutputEvent) error { messages := make([]*sarama.ProducerMessage, len(updates)) for i := range updates { - value, err := json.Marshal(updates[i]) + value, err := json.ConfigCompatibleWithStandardLibrary.Marshal(updates[i]) if err != nil { return err } diff --git a/roomserver/internal/perform/perform_peek.go b/roomserver/internal/perform/perform_peek.go index 67c8b3682..e3e9c5caa 100644 --- a/roomserver/internal/perform/perform_peek.go +++ b/roomserver/internal/perform/perform_peek.go @@ -167,7 +167,7 @@ func (r *Peeker) performPeekRoomByID( ev, _ := r.DB.GetStateEvent(ctx, roomID, "m.room.history_visibility", "") if ev != nil { content := map[string]string{} - if err = json.Unmarshal(ev.Content(), &content); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(ev.Content(), &content); err != nil { util.GetLogger(ctx).WithError(err).Error("json.Unmarshal for history visibility failed") return } diff --git a/roomserver/internal/query/query_test.go b/roomserver/internal/query/query_test.go index 9198a2346..cefcc3d62 100644 --- a/roomserver/internal/query/query_test.go +++ b/roomserver/internal/query/query_test.go @@ -50,7 +50,7 @@ func (db *getEventDB) addFakeEvent(eventID string, authIDs []string) error { "auth_events": authEvents, } - eventJSON, err := json.Marshal(&builder) + eventJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(&builder) if err != nil { return err } diff --git a/roomserver/roomserver_test.go b/roomserver/roomserver_test.go index 53886c95e..f1d97b233 100644 --- a/roomserver/roomserver_test.go +++ b/roomserver/roomserver_test.go @@ -50,7 +50,7 @@ func (p *dummyProducer) SendMessage(msg *sarama.ProducerMessage) (partition int3 b := json.RawMessage(be) fmt.Println("SENDING >>>>>>>> ", string(b)) var out api.OutputEvent - err = json.Unmarshal(b, &out) + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(b, &out) if err != nil { return 0, 0, err } diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index 3bb28e702..6cc6f6e09 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -603,7 +603,7 @@ func extractRoomVersionFromCreateEvent(event gomatrixserverlib.Event) ( var createContent gomatrixserverlib.CreateContent // The m.room.create event contains an optional "room_version" key in // the event content, so we need to unmarshal that first. - if err = json.Unmarshal(event.Content(), &createContent); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Content(), &createContent); err != nil { return gomatrixserverlib.RoomVersion(""), err } // A room version was specified in the event content? diff --git a/roomserver/storage/sqlite3/events_table.go b/roomserver/storage/sqlite3/events_table.go index c953a1d0a..2baeceae4 100644 --- a/roomserver/storage/sqlite3/events_table.go +++ b/roomserver/storage/sqlite3/events_table.go @@ -489,6 +489,6 @@ func (s *eventStatements) SelectRoomNIDForEventNID( } func eventNIDsAsArray(eventNIDs []types.EventNID) string { - b, _ := json.Marshal(eventNIDs) + b, _ := json.ConfigCompatibleWithStandardLibrary.Marshal(eventNIDs) return string(b) } diff --git a/roomserver/storage/sqlite3/rooms_table.go b/roomserver/storage/sqlite3/rooms_table.go index 7399c3abd..ee920ff79 100644 --- a/roomserver/storage/sqlite3/rooms_table.go +++ b/roomserver/storage/sqlite3/rooms_table.go @@ -138,7 +138,7 @@ func (s *roomStatements) SelectRoomInfo(ctx context.Context, roomID string) (*ty return nil, err } var latestNIDs []int64 - if err = json.Unmarshal([]byte(latestNIDsJSON), &latestNIDs); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(latestNIDsJSON), &latestNIDs); err != nil { return nil, err } info.IsStub = len(latestNIDs) == 0 @@ -181,7 +181,7 @@ func (s *roomStatements) SelectLatestEventNIDs( if err != nil { return nil, 0, err } - if err := json.Unmarshal([]byte(nidsJSON), &eventNIDs); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(nidsJSON), &eventNIDs); err != nil { return nil, 0, err } return eventNIDs, types.StateSnapshotNID(stateSnapshotNID), nil @@ -199,7 +199,7 @@ func (s *roomStatements) SelectLatestEventsNIDsForUpdate( if err != nil { return nil, 0, 0, err } - if err := json.Unmarshal([]byte(nidsJSON), &eventNIDs); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(nidsJSON), &eventNIDs); err != nil { return nil, 0, 0, err } return eventNIDs, types.EventNID(lastEventSentNID), types.StateSnapshotNID(stateSnapshotNID), nil diff --git a/roomserver/storage/sqlite3/state_snapshot_table.go b/roomserver/storage/sqlite3/state_snapshot_table.go index 7e3c7fcd3..a81ac815f 100644 --- a/roomserver/storage/sqlite3/state_snapshot_table.go +++ b/roomserver/storage/sqlite3/state_snapshot_table.go @@ -73,7 +73,7 @@ func NewSqliteStateSnapshotTable(db *sql.DB) (tables.StateSnapshot, error) { func (s *stateSnapshotStatements) InsertState( ctx context.Context, txn *sql.Tx, roomNID types.RoomNID, stateBlockNIDs []types.StateBlockNID, ) (stateNID types.StateSnapshotNID, err error) { - stateBlockNIDsJSON, err := json.Marshal(stateBlockNIDs) + stateBlockNIDsJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(stateBlockNIDs) if err != nil { return } @@ -116,7 +116,7 @@ func (s *stateSnapshotStatements) BulkSelectStateBlockNIDs( if err := rows.Scan(&result.StateSnapshotNID, &stateBlockNIDsJSON); err != nil { return nil, err } - if err := json.Unmarshal([]byte(stateBlockNIDsJSON), &result.StateBlockNIDs); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(stateBlockNIDsJSON), &result.StateBlockNIDs); err != nil { return nil, err } } diff --git a/syncapi/consumers/clientapi.go b/syncapi/consumers/clientapi.go index c2b95e446..ee667a6a2 100644 --- a/syncapi/consumers/clientapi.go +++ b/syncapi/consumers/clientapi.go @@ -71,7 +71,7 @@ func (s *OutputClientDataConsumer) Start() error { func (s *OutputClientDataConsumer) onMessage(msg *sarama.ConsumerMessage) error { // Parse out the event JSON var output eventutil.AccountData - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("client API server output log: message parse failure") return nil diff --git a/syncapi/consumers/eduserver_sendtodevice.go b/syncapi/consumers/eduserver_sendtodevice.go index ab555b443..cfd5cc44a 100644 --- a/syncapi/consumers/eduserver_sendtodevice.go +++ b/syncapi/consumers/eduserver_sendtodevice.go @@ -74,7 +74,7 @@ func (s *OutputSendToDeviceEventConsumer) Start() error { func (s *OutputSendToDeviceEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { var output api.OutputSendToDeviceEvent - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("EDU server output log: message parse failure") return err diff --git a/syncapi/consumers/eduserver_typing.go b/syncapi/consumers/eduserver_typing.go index b82f6f798..138e2d2af 100644 --- a/syncapi/consumers/eduserver_typing.go +++ b/syncapi/consumers/eduserver_typing.go @@ -75,7 +75,7 @@ func (s *OutputTypingEventConsumer) Start() error { func (s *OutputTypingEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { var output api.OutputTypingEvent - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("EDU server output log: message parse failure") return nil diff --git a/syncapi/consumers/keychange.go b/syncapi/consumers/keychange.go index a225258d8..4d7512cf8 100644 --- a/syncapi/consumers/keychange.go +++ b/syncapi/consumers/keychange.go @@ -100,7 +100,7 @@ func (s *OutputKeyChangeEventConsumer) onMessage(msg *sarama.ConsumerMessage) er defer s.updateOffset(msg) var output api.DeviceMessage - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Error("syncapi: failed to unmarshal key change event from key server") return err diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go index a1c85af1e..08f5d6070 100644 --- a/syncapi/consumers/roomserver.go +++ b/syncapi/consumers/roomserver.go @@ -79,7 +79,7 @@ func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { // Parse out the event JSON var output api.OutputEvent - if err := json.Unmarshal(msg.Value, &output); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream log.WithError(err).Errorf("roomserver output log: message parse failure") return nil diff --git a/syncapi/routing/filter.go b/syncapi/routing/filter.go index 05293b46a..8db6e93a7 100644 --- a/syncapi/routing/filter.go +++ b/syncapi/routing/filter.go @@ -94,7 +94,7 @@ func PutFilter( } } - if err = json.Unmarshal(body, &filter); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(body, &filter); err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()), diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go index 5054d8df0..fb71e295b 100644 --- a/syncapi/storage/postgres/current_room_state_table.go +++ b/syncapi/storage/postgres/current_room_state_table.go @@ -237,12 +237,12 @@ func (s *currentRoomStateStatements) UpsertRoomState( // Parse content as JSON and search for an "url" key containsURL := false var content map[string]interface{} - if json.Unmarshal(event.Content(), &content) != nil { + if json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Content(), &content) != nil { // Set containsURL to true if url is present _, containsURL = content["url"] } - headeredJSON, err := json.Marshal(event) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } @@ -285,7 +285,7 @@ func rowsToEvents(rows *sql.Rows) ([]gomatrixserverlib.HeaderedEvent, error) { } // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, err } result = append(result, ev) @@ -306,7 +306,7 @@ func (s *currentRoomStateStatements) SelectStateEvent( return nil, err } var ev gomatrixserverlib.HeaderedEvent - if err = json.Unmarshal(res, &ev); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(res, &ev); err != nil { return nil, err } return &ev, err diff --git a/syncapi/storage/postgres/filter_table.go b/syncapi/storage/postgres/filter_table.go index 66bcf0158..87f7823ed 100644 --- a/syncapi/storage/postgres/filter_table.go +++ b/syncapi/storage/postgres/filter_table.go @@ -85,7 +85,7 @@ func (s *filterStatements) SelectFilter( // Unmarshal JSON into Filter struct var filter gomatrixserverlib.Filter - if err = json.Unmarshal(filterData, &filter); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(filterData, &filter); err != nil { return nil, err } return &filter, nil @@ -97,7 +97,7 @@ func (s *filterStatements) InsertFilter( var existingFilterID string // Serialise json - filterJSON, err := json.Marshal(filter) + filterJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(filter) if err != nil { return "", err } diff --git a/syncapi/storage/postgres/invites_table.go b/syncapi/storage/postgres/invites_table.go index 05f6782e8..d25af895b 100644 --- a/syncapi/storage/postgres/invites_table.go +++ b/syncapi/storage/postgres/invites_table.go @@ -95,7 +95,7 @@ func (s *inviteEventsStatements) InsertInviteEvent( ctx context.Context, txn *sql.Tx, inviteEvent gomatrixserverlib.HeaderedEvent, ) (streamPos types.StreamPosition, err error) { var headeredJSON []byte - headeredJSON, err = json.Marshal(inviteEvent) + headeredJSON, err = json.ConfigCompatibleWithStandardLibrary.Marshal(inviteEvent) if err != nil { return } @@ -150,7 +150,7 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange( } var event gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventJSON, &event); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventJSON, &event); err != nil { return nil, nil, err } diff --git a/syncapi/storage/postgres/output_room_events_table.go b/syncapi/storage/postgres/output_room_events_table.go index 2bfe79445..6ceee2a8c 100644 --- a/syncapi/storage/postgres/output_room_events_table.go +++ b/syncapi/storage/postgres/output_room_events_table.go @@ -168,7 +168,7 @@ func NewPostgresEventsTable(db *sql.DB) (tables.Events, error) { } func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error { - headeredJSON, err := json.Marshal(event) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } @@ -232,7 +232,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange( // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, nil, err } needSet := stateNeeded[ev.RoomID()] @@ -289,13 +289,13 @@ func (s *outputRoomEventsStatements) InsertEvent( // Parse content as JSON and search for an "url" key containsURL := false var content map[string]interface{} - if json.Unmarshal(event.Content(), &content) != nil { + if json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Content(), &content) != nil { // Set containsURL to true if url is present _, containsURL = content["url"] } var headeredJSON []byte - headeredJSON, err = json.Marshal(event) + headeredJSON, err = json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return } @@ -426,7 +426,7 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) { } // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, err } diff --git a/syncapi/storage/postgres/send_to_device_table.go b/syncapi/storage/postgres/send_to_device_table.go index ce3fa6cec..eb03c6c7d 100644 --- a/syncapi/storage/postgres/send_to_device_table.go +++ b/syncapi/storage/postgres/send_to_device_table.go @@ -144,7 +144,7 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages( UserID: userID, DeviceID: deviceID, } - if err = json.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil { return } if sentByToken != nil { diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 79aba0f29..4a6148276 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -547,7 +547,7 @@ func (d *Database) addTypingDeltaToResponse( ev := gomatrixserverlib.ClientEvent{ Type: gomatrixserverlib.MTyping, } - ev.Content, err = json.Marshal(map[string]interface{}{ + ev.Content, err = json.ConfigCompatibleWithStandardLibrary.Marshal(map[string]interface{}{ "user_ids": typingUsers, }) if err != nil { @@ -1281,7 +1281,7 @@ func (d *Database) SendToDeviceUpdatesWaiting( func (d *Database) StoreNewSendForDeviceMessage( ctx context.Context, streamPos types.StreamPosition, userID, deviceID string, event gomatrixserverlib.SendToDeviceEvent, ) (types.StreamPosition, error) { - j, err := json.Marshal(event) + j, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return streamPos, err } diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go index 8d9c0f0f4..25ef36a7a 100644 --- a/syncapi/storage/sqlite3/current_room_state_table.go +++ b/syncapi/storage/sqlite3/current_room_state_table.go @@ -226,12 +226,12 @@ func (s *currentRoomStateStatements) UpsertRoomState( // Parse content as JSON and search for an "url" key containsURL := false var content map[string]interface{} - if json.Unmarshal(event.Content(), &content) != nil { + if json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Content(), &content) != nil { // Set containsURL to true if url is present _, containsURL = content["url"] } - headeredJSON, err := json.Marshal(event) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } @@ -296,7 +296,7 @@ func rowsToEvents(rows *sql.Rows) ([]gomatrixserverlib.HeaderedEvent, error) { } // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, err } result = append(result, ev) @@ -317,7 +317,7 @@ func (s *currentRoomStateStatements) SelectStateEvent( return nil, err } var ev gomatrixserverlib.HeaderedEvent - if err = json.Unmarshal(res, &ev); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(res, &ev); err != nil { return nil, err } return &ev, err diff --git a/syncapi/storage/sqlite3/filter_table.go b/syncapi/storage/sqlite3/filter_table.go index e1a926ab7..1fed8ba3b 100644 --- a/syncapi/storage/sqlite3/filter_table.go +++ b/syncapi/storage/sqlite3/filter_table.go @@ -89,7 +89,7 @@ func (s *filterStatements) SelectFilter( // Unmarshal JSON into Filter struct var filter gomatrixserverlib.Filter - if err = json.Unmarshal(filterData, &filter); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal(filterData, &filter); err != nil { return nil, err } return &filter, nil @@ -101,7 +101,7 @@ func (s *filterStatements) InsertFilter( var existingFilterID string // Serialise json - filterJSON, err := json.Marshal(filter) + filterJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(filter) if err != nil { return "", err } diff --git a/syncapi/storage/sqlite3/invites_table.go b/syncapi/storage/sqlite3/invites_table.go index 628936b4e..6581ee164 100644 --- a/syncapi/storage/sqlite3/invites_table.go +++ b/syncapi/storage/sqlite3/invites_table.go @@ -100,7 +100,7 @@ func (s *inviteEventsStatements) InsertInviteEvent( } var headeredJSON []byte - headeredJSON, err = json.Marshal(inviteEvent) + headeredJSON, err = json.ConfigCompatibleWithStandardLibrary.Marshal(inviteEvent) if err != nil { return } @@ -161,7 +161,7 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange( } var event gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventJSON, &event); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventJSON, &event); err != nil { return nil, nil, err } if deleted { diff --git a/syncapi/storage/sqlite3/output_room_events_table.go b/syncapi/storage/sqlite3/output_room_events_table.go index 3ae9c49ba..ede775300 100644 --- a/syncapi/storage/sqlite3/output_room_events_table.go +++ b/syncapi/storage/sqlite3/output_room_events_table.go @@ -161,7 +161,7 @@ func NewSqliteEventsTable(db *sql.DB, streamID *streamIDStatements) (tables.Even } func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error { - headeredJSON, err := json.Marshal(event) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return err } @@ -231,7 +231,7 @@ func (s *outputRoomEventsStatements) SelectStateInRange( // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, nil, err } needSet := stateNeeded[ev.RoomID()] @@ -288,22 +288,22 @@ func (s *outputRoomEventsStatements) InsertEvent( // Parse content as JSON and search for an "url" key containsURL := false var content map[string]interface{} - if json.Unmarshal(event.Content(), &content) != nil { + if json.ConfigCompatibleWithStandardLibrary.Unmarshal(event.Content(), &content) != nil { // Set containsURL to true if url is present _, containsURL = content["url"] } var headeredJSON []byte - headeredJSON, err := json.Marshal(event) + headeredJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(event) if err != nil { return 0, err } - addStateJSON, err := json.Marshal(addState) + addStateJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(addState) if err != nil { return 0, err } - removeStateJSON, err := json.Marshal(removeState) + removeStateJSON, err := json.ConfigCompatibleWithStandardLibrary.Marshal(removeState) if err != nil { return 0, err } @@ -441,7 +441,7 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) { } // TODO: Handle redacted events var ev gomatrixserverlib.HeaderedEvent - if err := json.Unmarshal(eventBytes, &ev); err != nil { + if err := json.ConfigCompatibleWithStandardLibrary.Unmarshal(eventBytes, &ev); err != nil { return nil, err } @@ -464,12 +464,12 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) { func unmarshalStateIDs(addIDsJSON, delIDsJSON string) (addIDs []string, delIDs []string, err error) { if len(addIDsJSON) > 0 { - if err = json.Unmarshal([]byte(addIDsJSON), &addIDs); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(addIDsJSON), &addIDs); err != nil { return } } if len(delIDsJSON) > 0 { - if err = json.Unmarshal([]byte(delIDsJSON), &delIDs); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(delIDsJSON), &delIDs); err != nil { return } } diff --git a/syncapi/storage/sqlite3/send_to_device_table.go b/syncapi/storage/sqlite3/send_to_device_table.go index f0a03a017..6e096e66f 100644 --- a/syncapi/storage/sqlite3/send_to_device_table.go +++ b/syncapi/storage/sqlite3/send_to_device_table.go @@ -137,7 +137,7 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages( UserID: userID, DeviceID: deviceID, } - if err = json.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil { + if err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil { return } if sentByToken != nil { diff --git a/syncapi/sync/notifier_test.go b/syncapi/sync/notifier_test.go index 6184b7fc3..7af8bc1c6 100644 --- a/syncapi/sync/notifier_test.go +++ b/syncapi/sync/notifier_test.go @@ -50,7 +50,7 @@ var ( func init() { var err error - err = json.Unmarshal([]byte(`{ + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(`{ "_room_version": "1", "type": "m.room.message", "content": { @@ -66,7 +66,7 @@ func init() { if err != nil { panic(err) } - err = json.Unmarshal([]byte(`{ + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(`{ "_room_version": "1", "type": "m.room.member", "state_key": "`+bob+`", @@ -82,7 +82,7 @@ func init() { if err != nil { panic(err) } - err = json.Unmarshal([]byte(`{ + err = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(`{ "_room_version": "1", "type": "m.room.member", "state_key": "`+bob+`", diff --git a/syncapi/sync/request.go b/syncapi/sync/request.go index 671eb66bd..ca1575597 100644 --- a/syncapi/sync/request.go +++ b/syncapi/sync/request.go @@ -76,7 +76,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat if filterQuery[0] == '{' { // attempt to parse the timeline limit at least var f filter - err := json.Unmarshal([]byte(filterQuery), &f) + err := json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(filterQuery), &f) if err == nil && f.Room.Timeline.Limit != nil { timelineLimit = *f.Room.Timeline.Limit } diff --git a/syncapi/types/types.go b/syncapi/types/types.go index c9d9c1f47..e8a7bdbf9 100644 --- a/syncapi/types/types.go +++ b/syncapi/types/types.go @@ -480,7 +480,7 @@ func NewInviteResponse(event gomatrixserverlib.HeaderedEvent) *InviteResponse { // If there is then unmarshal it into the response. This will contain the // partial room state such as join rules, room name etc. if inviteRoomState := gjson.GetBytes(event.Unsigned(), "invite_room_state"); inviteRoomState.Exists() { - _ = json.Unmarshal([]byte(inviteRoomState.Raw), &res.InviteState.Events) + _ = json.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(inviteRoomState.Raw), &res.InviteState.Events) } // Then we'll see if we can create a partial of the invite event itself. @@ -488,7 +488,7 @@ func NewInviteResponse(event gomatrixserverlib.HeaderedEvent) *InviteResponse { format, _ := event.RoomVersion.EventFormat() inviteEvent := gomatrixserverlib.ToClientEvent(event.Unwrap(), format) inviteEvent.Unsigned = nil - if ev, err := json.Marshal(inviteEvent); err == nil { + if ev, err := json.ConfigCompatibleWithStandardLibrary.Marshal(inviteEvent); err == nil { res.InviteState.Events = append(res.InviteState.Events, ev) } diff --git a/syncapi/types/types_test.go b/syncapi/types/types_test.go index 85df50378..e9ec5fa1d 100644 --- a/syncapi/types/types_test.go +++ b/syncapi/types/types_test.go @@ -102,7 +102,7 @@ func TestNewInviteResponse(t *testing.T) { } res := NewInviteResponse(ev.Headered(gomatrixserverlib.RoomVersionV5)) - j, err := json.Marshal(res) + j, err := json.ConfigCompatibleWithStandardLibrary.Marshal(res) if err != nil { t.Fatal(err) }