Repository navigation
fix(nodeenv): read a config value raw when interpolation fails - #449
Conversation
b81323d to
bd97bdb
Compare
|
Rebased onto current master; kept the % config changelog entry alongside the recent -p PATH fix. |
ekalinin
left a comment
There was a problem hiding this comment.
Thanks for the patch! Two things before merge.
-
interpolation=Noneis the fix #440 suggests, but the issue missed that./setup.cfgis also read by setuptools, which interpolates every section of it,[nodeenv]included. With this change no spelling of a percent-encoded login insetup.cfgworks for both tools: withp%40ss,pip install .of that project fails withInterpolationSyntaxError, andp%%40ss, which setuptools accepts, now reaches nodeenv asp%%40ssand is sent as the passwordp%@ss. On masterp%%40ssworks for both. The change also turns off%(name)sreferences:mirror = %(base)s/nodejswithbasein[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
InterpolationErrorimported fromconfigparser. 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%40ssandp%%40ssboth givep%40ss,%(base)sis expanded, and pip builds the project withp%%40ssinsetup.cfg. TheCHANGESentry 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 behaviorsetup.cfgdepends 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.
|
Thanks, that's a better fix. Switched to your approach in a26efea: interpolation stays on and the raw value is read only on |
a26efea to
f7f6a47
Compare
|
Thanks! |
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)sreferences keep working.The test covers both
%40and%%40. Unit tests and flake8 onnodeenv.pypass locally; the Windows, zsh and fish shell tests were skipped since I don't have those here.toxpasses: the tests and flake8CHANGEShas an entry underVersion [unreleased], if nodeenv's behavior changesREADME.rstis updated, if the change affects what it documentstype(scope): subject