Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-473

toExtJSON does not escape double quotes in strings

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 0.0.17
    • Affects Version/s: None
    • Component/s: JSON & ExtJSON
    • Labels:
      None

      I am pulling entries from a collection, and converting each to JSON.

      The JSON which is generated is not always "legal": the mongo go driver does not seem to escape quotes in value strings, so the generated JSON is not compliant.

      This seems like a pretty serious bug - Am I doing anything wrong? Relevant code pasted below.

       

      func streamMongoCursorAsJSONResponse(w http.ResponseWriter, cur mongo.Cursor) {
          w.Header().Set("Content-Type", "application/json")
          w.Write([]byte("["))
          count := 0
          for cur.Next(context.Background()) {
              elem := bson.NewDocument()
              err := cur.Decode(elem)
              if err != nil {
                  continue
              }
              if count != 0 {
                  w.Write([]byte(",\n"))
              }
              w.Write([]byte(elem.ToExtJSON(false)))
              count++
          }
          w.Write([]byte("]"))
      }
      

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            gpean Gregoire Pean
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: