Skip to content

A bad %(name)s reference in a config value no longer raises an error #456

Closed

Description

@ekalinin

Since #449 (02f4ce3), Config._load reads the raw value on any InterpolationError:

                    try:
                        val = ini_file.get(section, attr)
                    except InterpolationError:
                        # A percent-encoded mirror login, #440
                        val = ini_file.get(section, attr, raw=True)

The fallback is meant for a % that isn't followed by % or (, as in a percent-encoded mirror login, which raises InterpolationSyntaxError. But InterpolationError also covers InterpolationMissingOptionError (a %(name)s reference to a key that doesn't exist, such as a typo) and InterpolationDepthError (a reference loop). Before #449 both raised an error that named the key. Now the value is read as is, and the failure shows up later and points somewhere else: a mirror without :// is taken for a domain, so nodeenv tries to download from https://%(bsae)s/....

Reproduce

On master (02f4ce3), Python 3.14, macOS:

$ cat setup.cfg
[DEFAULT]
base = https://mirror.example

[nodeenv]
mirror = %(bsae)s/nodejs
$ nodeenv --list
Error: cannot download https://%(bsae)s/nodejs/download/release/index.json: [Errno 8] nodename nor servname provided, or not known

Before #449 (b68eb29) the same file gave:

configparser.InterpolationMissingOptionError: Bad value substitution: option 'mirror' in section 'nodeenv' contains an interpolation key 'bsae' which is not a valid option name. Raw value: '%(bsae)s/nodejs'

mirror = %(mirror)s/nodejs behaves the same way: InterpolationDepthError before #449, cannot download https://%(mirror)s/nodejs/... now.

Possible fix

Catch only the error a stray % raises:

from configparser import ConfigParser, InterpolationSyntaxError
...
                    except InterpolationSyntaxError:

With it p%40ss and p%%40ss still both give p%40ss, and the two files above raise the same errors as before #449. A valid percent-encoded URL never contains %(, so this doesn't take away anything #440 needs. A test case with a missing key that expects InterpolationMissingOptionError would pin it.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions