Skip to content

fix(nodeenv): read a config value raw when interpolation fails - #449

Merged
ekalinin merged 2 commits into
ekalinin:masterfrom
r3wretrhy:fix-config-percent
Oct 30, 2026
Merged

ekalinin merged 2 commits into
ekalinin:masterfrom
r3wretrhy:fix-config-percent

Conversation

@r3wretrhy

@r3wretrhy r3wretrhy commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #440

ConfigParser interpolation stays on, and a value is read raw only when interpolating it fails. A percent-encoded mirror login (the form the README recommends for --mirror) can then sit in setup.cfg or ~/.nodeenvrc without breaking nodeenv in that directory, while %% still gives % (setup.cfg needs that, since setuptools reads it too) and %(name)s references keep working.

The test covers both %40 and %%40. Unit tests and flake8 on nodeenv.py pass locally; the Windows, zsh and fish shell tests were skipped since I don't have those here.

  • Tests cover the change
  • tox passes: the tests and flake8
  • CHANGES has an entry under Version [unreleased], if nodeenv's behavior changes
  • README.rst is updated, if the change affects what it documents
  • The title has the form type(scope): subject

@r3wretrhy

Copy link
Copy Markdown
Contributor Author

Rebased onto current master; kept the % config changelog entry alongside the recent -p PATH fix.

@ekalinin ekalinin left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! Two things before merge.

  • interpolation=None is the fix #440 suggests, but the issue missed that ./setup.cfg is also read by setuptools, which interpolates every section of it, [nodeenv] included. With this change no spelling of a percent-encoded login in setup.cfg works for both tools: with p%40ss, pip install . of that project fails with InterpolationSyntaxError, and p%%40ss, which setuptools accepts, now reaches nodeenv as p%%40ss and is sent as the password p%@ss. On master p%%40ss works for both. The change also turns off %(name)s references: mirror = %(base)s/nodejs with base in [DEFAULT] is now read as is.

    Keeping the interpolation and reading the raw value only when it fails covers all of these:

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

    with InterpolationError imported from configparser. A valid percent-encoded URL never contains %% or %(, so a value that does interpolate is one where the % was meant for ConfigParser. I checked it with setuptools 84 and Python 3.14: p%40ss and p%%40ss both give p%40ss, %(base)s is expanded, and pip builds the project with p%%40ss in setup.cfg. The CHANGES entry would then change too, something like:

    - A ``%`` in a ``[nodeenv]`` config value, such as a percent-encoded
      mirror login, no longer crashes nodeenv: a value that can't be
      interpolated is read as written. ``%%`` still gives ``%``, which
      ``setup.cfg`` needs, as setuptools reads that file too
      `#440 <https://github.com/ekalinin/nodeenv/issues/440>`_
  • The test only checks %40. A %% case would pin the behavior setup.cfg depends on:

    @pytest.mark.parametrize('mirror, expected', [
        ('https://user:p%[email protected]/nodejs',
         'https://user:p%[email protected]/nodejs'),
        ('https://user:p%%[email protected]/nodejs',
         'https://user:p%[email protected]/nodejs'),
    ])
    def test_config_keeps_percent_signs(tmpdir, mirror, expected):
        """A % that ConfigParser can't interpolate is read as is, see #440"""
        rc = tmpdir.join('nodeenvrc')
        rc.write('[nodeenv]\nmirror = %s\n' % mirror)
        try:
            nodeenv.Config._load([str(rc)])
            assert nodeenv.Config.mirror == expected
        finally:
            nodeenv.Config.mirror = nodeenv.Config._default['mirror']

    It fails on master for %40, on this branch for %%40, and passes with the change above.

@r3wretrhy

Copy link
Copy Markdown
Contributor Author

Thanks, that's a better fix. Switched to your approach in a26efea: interpolation stays on and the raw value is read only on InterpolationError. Updated the CHANGES entry to your wording and parametrized the test with the %%40 case. The config tests pass locally.

@r3wretrhy r3wretrhy changed the title fix(nodeenv): read config values without interpolation fix(nodeenv): read a config value raw when interpolation fails Oct 29, 2026
@ekalinin
ekalinin merged commit 02f4ce3 into ekalinin:master Oct 30, 2026
26 checks passed
@ekalinin

Copy link
Copy Markdown
Owner

Thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A % in a [nodeenv] config value crashes nodeenv

2 participants