From 348efa68a7490388d0834ce2d142cf31461c4807 Mon Sep 17 00:00:00 2001
From: Daniel Farina <daniel@heroku.com>
Date: Wed, 6 Jun 2012 14:48:12 -0700
Subject: [PATCH] libpq: error on unknown parameters in URIs rather than warn

This rectifies an inconsistency with how un-recognized parameters are
treated between the URI format accepted by libpq and the older
connection string format.

The traditional connection string format would immediately exit with
an error when a connection string key is set that is not recognized by
libpq, and the URI parsing previously ignored and warned in the same
situation.  Now it also exits with a very similar (but non-identical)
error message, to facilitate diagnosis.

This is pursuant to the conversation at
http://archives.postgresql.org/pgsql-hackers/2012-06/msg00122.php

Signed-off-by: Daniel Farina <daniel@heroku.com>
---
 src/interfaces/libpq/fe-connect.c      |    8 +++++---
 src/interfaces/libpq/test/expected.out |    8 ++++----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 960811f..33daaec 100644
*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
***************
*** 4874,4882 **** conninfo_uri_parse_params(char *params,
  				return false;
  			}
  
! 			fprintf(stderr,
! 					libpq_gettext("WARNING: ignoring unrecognized URI query parameter: %s\n"),
! 					keyword);
  		}
  		if (malloced)
  		{
--- 4874,4884 ----
  				return false;
  			}
  
! 			printfPQExpBuffer(errorMessage,
! 							  libpq_gettext(
! 								  "invalid URI query parameter \"%s\"\n"),
! 							  keyword);
! 			return false;
  		}
  		if (malloced)
  		{
*** a/src/interfaces/libpq/test/expected.out
--- b/src/interfaces/libpq/test/expected.out
***************
*** 59,66 **** trying postgresql://host/db?u%73er=someotheruser&port=12345
  user='someotheruser' dbname='db' host='host' port='12345' (inet)
  
  trying postgresql://host/db?u%7aer=someotheruser&port=12345
! WARNING: ignoring unrecognized URI query parameter: uzer
! dbname='db' host='host' port='12345' (inet)
  
  trying postgresql://host:12345?user=uri-user
  user='uri-user' host='host' port='12345' (inet)
--- 59,66 ----
  user='someotheruser' dbname='db' host='host' port='12345' (inet)
  
  trying postgresql://host/db?u%7aer=someotheruser&port=12345
! uri-regress: invalid URI query parameter "uzer"
! 
  
  trying postgresql://host:12345?user=uri-user
  user='uri-user' host='host' port='12345' (inet)
***************
*** 102,109 **** trying postgres://?host=/path/to/socket/dir
  host='/path/to/socket/dir' (local)
  
  trying postgresql://host?uzer=
! WARNING: ignoring unrecognized URI query parameter: uzer
! host='host' (inet)
  
  trying postgre://
  uri-regress: missing "=" after "postgre://" in connection info string
--- 102,109 ----
  host='/path/to/socket/dir' (local)
  
  trying postgresql://host?uzer=
! uri-regress: invalid URI query parameter "uzer"
! 
  
  trying postgre://
  uri-regress: missing "=" after "postgre://" in connection info string
