lib / pq

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

If password is "" in dsn, I get a error options after parseOpts #879

Open YoungWing opened 5 years ago

YoungWing commented 5 years ago

test code like this:

        o := make(map[string]string)
    dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
        "localhost",
        5432,
        "test",
        "",
        "testDB",
    )
    parseOpts(dsn, o)
    fmt.Println(o)

output:

map[host:localhost password:dbname=testDB port:5432 sslmode:disable user:test]

in this map, we can see the passwd value is that "dbname=testDB" rather than ""

In this case,it is a wrong dsn parser?

Or when my passwd is null, I can only put passwd end of dsn,like this:

dsn := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable password=%s",
        "localhost",
        5432,
        "test",
        "testDB",
        "",
    ) 
cbandy commented 5 years ago

Blank values need to be wrapped in single quotes. The package docs could be more explicit about this.