[GODRIVER-1456] Extended JSON writer should escape keys Created: 02/Jan/20  Updated: 28/Oct/23  Resolved: 07/Jan/20

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: None
Fix Version/s: 1.2.1

Type: Bug Priority: Major - P3
Reporter: Matthew Chiaravalloti Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
causes TOOLS-2453 Index keys not escaped correctly Closed
Related
Case:

 Description   

The extJSONValueWriter.WriteDocumenElement() method should escape keys when writing. The BI Connector team encountered an issue where a key with these characters "\usb#" could not be unmarshalled since that is not a valid unicode sequence. A simpler example is:

func main() {
	key := "\""
	doc := bson.D{{Key: key, Value: 1}}
	b, err := bson.MarshalExtJSON(&doc, false, false)
	if err != nil {
		fmt.Printf("marshal error: %v\n", err)
		return
	}
 
	fmt.Printf("doc: %s\n", string(b))
 
	err = bson.UnmarshalExtJSON(b, false, &doc)
	if err != nil {
		fmt.Printf("unmarshal error: %v\n", err)
	}
}

This outputs:

doc: {""":1}
unmarshal error: invalid JSON input: missing colon after key ""

https://github.com/mongodb/mongo-go-driver/blob/b5d915e43f066f88d5ea7863ec42a314a9d877ad/bson/bsonrw/extjson_writer.go#L539

I believe this is the only line that requires a change; the key should be escaped before writing.



 Comments   
Comment by Ryan Chipman [ 08/Jan/20 ]

BI Connector 2.13.3, which incorporates this fix, has been released. Thanks all for the expedited fix and release!

Comment by Githook User [ 07/Jan/20 ]

Author:

{'name': 'iwysiu', 'email': 'isabella.siu@10gen.com', 'username': 'iwysiu'}

Message: GODRIVER-1456 make extJSONValueWriter escape keys (#270)
Branch: release/1.2
https://github.com/mongodb/mongo-go-driver/commit/21d600473efeade017b59fd84e98a14134f5c713

Comment by Githook User [ 07/Jan/20 ]

Author:

{'name': 'iwysiu', 'email': 'isabella.siu@10gen.com', 'username': 'iwysiu'}

Message: GODRIVER-1456 make extJSONValueWriter escape keys (#270)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/60c9e0fe2b1d2d0ac9d9f576dfff48278006388f

Comment by Chandler Wyatt [ 07/Jan/20 ]

Hi All,

I was wondering if we could establish a ballpark ETA for release of this bug fix. After a discussion with the CAE for the customer who encountered this bug (Utelogy), it seems that the customer is now considering moving away from mongo due to this issue, which is severely impacting the operability of their BI Connector, and preventing their move to production.

I think if we can let the customer see the light at the end of the tunnel, we can get them off the ledge. I greatly appreciate your work on this and your consideration of establishing an ETA for the release. Thank you very much!

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