Skip to content

Commit 68d40c5

Browse files
committed
Return the libpq default port when blank in conninfo
PQport may return null or empty string when the same is set in connection options. Internally, libpq falls back to its configured default any time it reads these.
1 parent b4a371d commit 68d40c5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ext/pg_connection.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,10 @@ static VALUE
702702
pgconn_port(VALUE self)
703703
{
704704
char* port = PQport(pg_get_pgconn(self));
705-
return INT2NUM(atoi(port));
705+
if (!port || port[0] == '\0')
706+
return INT2NUM(DEF_PGPORT);
707+
else
708+
return INT2NUM(atoi(port));
706709
}
707710

708711
/*

0 commit comments

Comments
 (0)