Support for colon characters in PostgreSQL socket path.

Google Cloud SQL instances are now using the following format for the name
of their socket <PROJECT-ID>:<REGION>:<INSTANCE_NAME>. We do that by
allowing to escape a colon in the socket directory name by doubling it, as
in the username field. It also allows to accept any character in the socket
directory name, which is a good cleanup.

Fix #621.
This commit is contained in:
Dimitri Fontaine 2017-08-30 15:22:42 +02:00
parent d5072d11e5
commit a9e8bfd4d7
3 changed files with 21 additions and 1 deletions

View File

@ -830,6 +830,20 @@ postgresql://unix:/tmp:54321/dbname
.
.IP
The \fInetloc\fR defaults to the value of the \fBPGHOST\fR environment variable, and if it is unset, to either the default \fBunix\fR socket path when running on a Unix system, and \fBlocalhost\fR otherwise\.
.
.IP
Socket path containing colons are supported by doubling the colons within the path, as in the following example:
.
.IP "" 4
.
.nf
postgresql://unix:/tmp/project::region::instance:5432/dbname
.
.fi
.
.IP "" 0
.
.IP "\(bu" 4
\fIdbname\fR

View File

@ -704,6 +704,11 @@ Where:
variable, and if it is unset, to either the default `unix` socket path
when running on a Unix system, and `localhost` otherwise.
Socket path containing colons are supported by doubling the colons
within the path, as in the following example:
postgresql://unix:/tmp/project::region::instance:5432/dbname
- *dbname*
Should be a proper identifier (letter followed by a mix of letters,

View File

@ -60,7 +60,8 @@
(or (member char #.(quote (coerce "/.-_" 'list)))
(alphanumericp char)))
(defrule socket-directory (and "unix:" (* (socket-directory-character-p character)))
(defrule socket-directory (and "unix:"
(* (or (not ":") doubled-colon)))
(:destructure (unix socket-directory)
(declare (ignore unix))
(list :unix (when socket-directory (text socket-directory)))))