lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.86k stars 908 forks source link

lib/pq incorrectly escapes input strings that are already escaped #1118

Open mohammadv184 opened 1 year ago

mohammadv184 commented 1 year ago

Description

When inserting a row into CockroachDB using ib/pq and the stmt.Exec function, the library incorrectly escapes special characters in the input string, resulting in an invalid JSON string being inserted into the database. It appears that the library is escaping the input string twice, even though it's already escaped.

Steps to Reproduce

  1. Prepare a statement for inserting a row into a CockroachDB table using pq.CopyIn.
  2. Call stmt.Exec with a value that contains special characters and is already escaped, such as {"body":"value with escaped special \" character"}.
  3. Check the inserted row in the database and observe that the special characters are incorrectly escaped, resulting in an invalid JSON string.

Expected Behavior

The library should correctly handle input strings that are already escaped and should not escape them again.

Actual Behavior

The library incorrectly escapes input strings that are already escaped, resulting in an invalid JSON string.

Versions

lib/pq version: v1.10.7 CockroachDB version: v22.2 Go version: go1.20.3 linux/amd64