@@ -799,6 +799,44 @@ func TestParseConfigKVTrailingBackslash(t *testing.T) {
799799 assert .Contains (t , err .Error (), "invalid backslash" )
800800}
801801
802+ // https://github.com/jackc/pgx/issues/2284
803+ // Multiple trailing spaces and trailing spaces after quoted values must be
804+ // accepted as valid keyword/value connection strings.
805+ func TestParseConfigKVTrailingWhitespace (t * testing.T ) {
806+ tests := []struct {
807+ name string
808+ connString string
809+ }{
810+ {
811+ name : "single trailing space" ,
812+ connString : "dbname=foo " ,
813+ },
814+ {
815+ name : "multiple trailing spaces" ,
816+ connString : "dbname=foo " ,
817+ },
818+ {
819+ name : "trailing tab" ,
820+ connString : "dbname=foo\t " ,
821+ },
822+ {
823+ name : "quoted value with trailing spaces" ,
824+ connString : "dbname='foo' " ,
825+ },
826+ {
827+ name : "two key-value pairs with trailing spaces" ,
828+ connString : "port=5432 dbname=foo " ,
829+ },
830+ }
831+
832+ for _ , tt := range tests {
833+ t .Run (tt .name , func (t * testing.T ) {
834+ _ , err := pgconn .ParseConfig (tt .connString )
835+ require .NoErrorf (t , err , "conn string %q should not produce an error" , tt .connString )
836+ })
837+ }
838+ }
839+
802840func TestConfigCopyReturnsEqualConfig (t * testing.T ) {
803841 connString := "postgres://jack:secret@localhost:5432/mydb?application_name=pgxtest&search_path=myschema&connect_timeout=5"
804842 original , err := pgconn .ParseConfig (connString )
0 commit comments