Browse Source

Put back functionality lost during DB API 2.0 conversion. Allo '/' to be
part of the "hostname" portion of the "URI". PostgreSQL allows using this
to specify location of the unix domain socket for communication with the
server. Example of such URL would be:

postgres://someuser@/var/run/sippy

Here the sippy is the database name, while /var/run is the location of the
socket. This change should be backward compatible since '/' is not
allowed in the database name.

Maxim Sobolev 17 years ago
parent
commit
dc24f971de
1 changed files with 6 additions and 0 deletions
  1. 6 0
      modules/db_postgres/pg_uri.c

+ 6 - 0
modules/db_postgres/pg_uri.c

@@ -169,6 +169,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
 				break;
 
 			case '/':
+				if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+					break;
 				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
 				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) 
 					goto err;
@@ -186,6 +188,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
 				break;
 
 			case '/':
+				if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+					break;
 				res->host = prev_token;
 				res->port = str2s(begin, uri->s + i - begin, 0);
 				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) 
@@ -203,6 +207,8 @@ static int parse_postgres_uri(struct pg_uri* res, str* uri)
 				break;
 
 			case '/':
+				if (memchr(uri->s + i + 1, '/', uri->len - i - 1) != NULL)
+					break;
 				if (dupl_string(&res->host, begin, uri->s + i) < 0) goto err;
 				if (dupl_string(&res->database, uri->s + i + 1, uri->s + uri->len) < 0) 
 					goto err;