Quote role name in test/authentication/t/003_peer.pl

Started by Yugo Nagata28 days ago3 messageshackers
Jump to latest
#1Yugo Nagata
nagata@sraoss.co.jp

Hi,

I noticed that test/authentication/t/003_peer.pl can fail when the system_user
name contains characters that require quoting in SQL, such as a hyphen.

The test creates a role using a name derived from the OS user:

$node->safe_psql('postgres', "CREATE ROLE $mapped_name LOGIN");

If $mapped_name contains a hyphen, this results in a syntax error.
The attached patch fixes this by properly quoting the role name:

$node->safe_psql('postgres', "CREATE ROLE \"$mapped_name\" LOGIN");

Regards,

Yugo Nagata

--
Yugo Nagata <nagata@sraoss.co.jp>

Attachments:

test_authentication_003_pear.patchtext/x-diff; name=test_authentication_003_pear.patchDownload+1-1
#2Michael Paquier
michael@paquier.xyz
In reply to: Yugo Nagata (#1)
Re: Quote role name in test/authentication/t/003_peer.pl

On Mon, Jul 27, 2026 at 01:38:57PM +0900, Yugo Nagata wrote:

If $mapped_name contains a hyphen, this results in a syntax error.
The attached patch fixes this by properly quoting the role name:

$node->safe_psql('postgres', "CREATE ROLE \"$mapped_name\" LOGIN");

# Create target role for \1 tests.
my $mapped_name = "test${regex_test_string}map${regex_test_string}user";
-$node->safe_psql('postgres', "CREATE ROLE $mapped_name LOGIN");
+$node->safe_psql('postgres', "CREATE ROLE \"$mapped_name\" LOGIN");

I doubt that this is worth beyond what you are proposing here, so just
applying double quotes are you are doing sounds good to me. Will fix
and backpatch on portability ground.
--
Michael

#3Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#2)
Re: Quote role name in test/authentication/t/003_peer.pl

On Mon, Jul 27, 2026 at 02:14:09PM +0900, Michael Paquier wrote:

I doubt that this is worth beyond what you are proposing here, so just
applying double quotes are you are doing sounds good to me. Will fix
and backpatch on portability ground.

Done as 5713b437abed, down to v19.
--
Michael