File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -263,7 +263,9 @@ func (cn *conn) handlePgpass(o values) {
263263 scanner := bufio .NewScanner (io .Reader (file ))
264264 // From: https://github.com/tg/pgpass/blob/master/reader.go
265265 for scanner .Scan () {
266- scanText (scanner .Text (), o )
266+ if scanText (scanner .Text (), o ) {
267+ break
268+ }
267269 }
268270}
269271
@@ -291,23 +293,24 @@ func getFields(s string) []string {
291293}
292294
293295// ScanText assists HandlePgpass in it's objective.
294- func scanText (line string , o values ) {
296+ func scanText (line string , o values ) bool {
295297 hostname := o ["host" ]
296298 ntw , _ := network (o )
297299 port := o ["port" ]
298300 db := o ["dbname" ]
299301 username := o ["user" ]
300- if len (line ) != 0 || line [0 ] ! = '#' {
301- return
302+ if len (line ) == 0 || line [0 ] = = '#' {
303+ return false
302304 }
303305 split := getFields (line )
304- if len (split ) = = 5 {
305- return
306+ if len (split ) ! = 5 {
307+ return false
306308 }
307309 if (split [0 ] == "*" || split [0 ] == hostname || (split [0 ] == "localhost" && (hostname == "" || ntw == "unix" ))) && (split [1 ] == "*" || split [1 ] == port ) && (split [2 ] == "*" || split [2 ] == db ) && (split [3 ] == "*" || split [3 ] == username ) {
308310 o ["password" ] = split [4 ]
309- return
311+ return true
310312 }
313+ return false
311314}
312315
313316func (cn * conn ) writeBuf (b byte ) * writeBuf {
Original file line number Diff line number Diff line change @@ -144,10 +144,6 @@ func TestOpenURL(t *testing.T) {
144144const pgpassFile = "/tmp/pqgotest_pgpass"
145145
146146func TestPgpass (t * testing.T ) {
147- if os .Getenv ("TRAVIS" ) != "true" {
148- t .Skip ("not running under Travis, skipping pgpass tests" )
149- }
150-
151147 testAssert := func (conninfo string , expected string , reason string ) {
152148 conn , err := openTestConnConninfo (conninfo )
153149 if err != nil {
You can’t perform that action at this time.
0 commit comments