Skip to content

Disable interpolation when reading the connection service file - #1395

Open
spicysharkco wants to merge 1 commit into
MagicStack:masterfrom
spicysharkco:fix-service-file-percent
Open

spicysharkco wants to merge 1 commit into
MagicStack:masterfrom
spicysharkco:fix-service-file-percent

Conversation

@spicysharkco

Copy link
Copy Markdown

A connection service file value that contains % makes connect() fail with configparser.InterpolationSyntaxError, for example password=pa%ss or a host or option value with a % in it. The error only appears once that service is selected, because the values are read lazily.

The service file is parsed with a default ConfigParser, which applies BasicInterpolation to every value. libpq has no such step: it takes the text after = as it is. The change creates the parser with interpolation=None, so values are used literally. A value written as %% to work around the error now reads as two percent signs, as it does in libpq.

Tested by changing the password in the test_service_database section of test_connect_connection_service_file to test%password. Without the change that test errors with '%' must be followed by '%' or '(', found: '%password'. With it, TestConnectParams passes (11 tests), and flake8 and mypy are clean.

#1376 re-indents the service file block in connect_utils.py, including this line, so whichever lands second needs a trivial rebase.

ConfigParser treated "%" in service file values as interpolation syntax,
so a password such as "pa%ss" raised InterpolationSyntaxError when the
service was selected. libpq reads the values literally.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant