-
Type:
Bug
-
Resolution: Works as Designed
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Summary
Trying to parse the following string (unescaped):
{"keyfileWindows" : "%SystemDrive%\KeyfileVersions\versions\keyfile"}
fails because JsonScanner#scanString recognizes everything beginning with }} as an escape character. {{\M is the above example is not a valid escape character, so there is an exception thrown while parsing this:
Exception in thread "main" org.bson.json.JsonParseException: Invalid escape sequence in JSON string '\K'. at org.bson.json.JsonScanner.scanString(JsonScanner.java:520) at org.bson.json.JsonScanner.nextToken(JsonScanner.java:92) at org.bson.json.JsonReader.popToken(JsonReader.java:504) at org.bson.json.JsonReader.readBsonType(JsonReader.java:155) at com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:400) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:167) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:67) at com.mongodb.BasicDBObject.parse(BasicDBObject.java:94) at com.mongodb.BasicDBObject.parse(BasicDBObject.java:81) at benchmark.BenchmarkMain.decodeUsingParse(BenchmarkMain.java:41) at benchmark.BenchmarkMain.main(BenchmarkMain.java:27)
I am using driver version 4.7.0.
How to Reproduce
BasicDBObject.parse("{ \"keyfileWindows\" : \"%SystemDrive%\\KeyfileVersions\\versions\\keyfile\" }");
Additional Background
The exception does not get thrown when using the (now deprecated) JSON#parse functionality provided in 3.11.x. The parsing is still incorrect, but that's irrelevant to the point of this ticket.