Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4689

BasicDBObject#parse Treats All Character Sequences Beginning With '\' as Escape Characters

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ramasai.tadepalli@mongodb.com Ramasai Tadepalli
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: