[SERVER-55450] JSON.stringify in Realm function does not encode correctly Created: 23/Mar/21  Updated: 24/Mar/21  Resolved: 24/Mar/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Blocker - P1
Reporter: Timmy Pandahouse Assignee: Eric Sedor
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

What I did:

Configure a Trigger function on a collection and log a property from a document:

{{exports = async (changeEvent) => { }}{{console.log(JSON.stringify(changeEvent && changeEvent.fullDocument && changeEvent.fullDocument.name)) }}}

 Create a document with a curly brace in the `name` property, e.g. `{ "name": "Test’s" }`

View the log entry for the create.

What I expected:

The log entry would show `Test’s`

What actually happened:

The log entry shows `Testâs`

Additional notes:

An example log entry is from our trigger named `fanx_data_legacy_dev` with the id `605a194e3684e76b32b532dd`.

This is not limited to the `console.log` output: our trigger function pushes the JSON.stringify'd document to SQS, and the encoding shows the incorrect `Testâs` as well.

Participants:

 Description   

When I use JSON.stringify on an object containing the curly quote character, e.g. `’`, in a triggered function, it is encoded to `â`.

This is affecting our very high visibility clients in the sport industry, e.g. the NCAA and others.



 Comments   
Comment by Eric Sedor [ 24/Mar/21 ]

Hi developers@panda.industries,

Unfortunately, because the SERVER project is for the core MongoDB server, we aren't able to investigate Realm/Atlas issues directly. With apology for the redirect, can you please reach out via Intercom (the round green button at the bottom right of the cluster view page in Atlas) if you need any follow-up to your prior communication there?

Gratefully,
Eric

Comment by Timmy Pandahouse [ 23/Mar/21 ]

As of now, this behavior has been corrected, e.g. curly quotes now are left as curly quotes and so on.

I cross posted to the community forum: https://developer.mongodb.com/community/forums/t/strings-are-encoded-incorrectly-in-atlas-triggered-function/100189

Since I was able to isolate this behavior to the MongoDB Atlas triggered function, I would still like follow-up on what occurred on your side, e.g. an incident report.

Comment by Timmy Pandahouse [ 23/Mar/21 ]

Actually this might be a bigger issue, not a JSON.stringify issue: if I simply `.toString()` it outputs the incorrect encoding.

E.g. instead of this:

exports = async (changeEvent) =>

{   console.log(JSON.stringify(changeEvent && changeEvent.fullDocument && changeEvent.fullDocument.name)) }

I simply do this:

exports = async (changeEvent) =>

{   console.log(changeEvent && changeEvent.fullDocument && changeEvent.fullDocument.name) }

the output is the same incorrect `Testâs` value.

Generated at Thu Feb 08 05:36:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.