Pgx: ParseDSN doesn't support single quotes, double quotes not handled correctly

Created on 4 Jan 2018  路  2Comments  路  Source: jackc/pgx

Hi,

thanks for this driver. I've been trying to use it with our DSN connection strings, but there seems to be some issues with ParseDSN.

According to https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNSTRING values containing spaces should be quoted with single quotes. That's not supported by ParseDSN in this package. Instead it supports double quotes, but unfortunately the double quotes are included as part of the value, which then becomes invalid, at least in some cases.

Program to reproduce

package main

import (
        "fmt"

        "github.com/jackc/pgx"
)

func main() {
        c, _ := pgx.ParseDSN(`host='foo bar' options="-c search_path=fooschema,public"`)
        fmt.Printf("%s\n", c.Host)
        fmt.Printf("%s\n", c.RuntimeParams["options"])
}

Expected output

foo bar
-c search_path=fooschema,public

or I suppose " isn't needed to be supported... it's not mentioned in the link above.

Actual output

'foo
"-c search_path=fooschema,public"
bug

Most helpful comment

I can try to implement a parser instead of regexp.

All 2 comments

Yeah, that's a bug. I poked at it a little bit and it looks like completely supporting the PostgreSQL DSN format (in particular backslash escapes) would require replacing the regexp approach with a simple parser.

I can try to implement a parser instead of regexp.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kokizzu picture kokizzu  路  6Comments

nick-jones picture nick-jones  路  4Comments

Oliver-Fish picture Oliver-Fish  路  4Comments

MOZGIII picture MOZGIII  路  4Comments

pengux picture pengux  路  3Comments