Skip to content

fix(nodeenv): escape glob characters in prebuilt paths - #447

Merged
ekalinin merged 3 commits into
ekalinin:masterfrom
tridev-tej:tejesh/fix-prebuilt-path-glob
Oct 31, 2026
Merged

ekalinin merged 3 commits into
ekalinin:masterfrom
tridev-tej:tejesh/fix-prebuilt-path-glob

Conversation

@tridev-tej

@tridev-tej tridev-tej commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Prebuilt installs treated destination paths and versions as glob patterns. Match archive names under a literal source directory and preserve the version boundary.

Fixes #441

  • Tests cover the change
  • tox -e py314 passes: tests and flake8
  • CHANGES has an unreleased entry
  • README.rst: no documentation change needed
  • Title uses type(scope): subject

@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.

  • glob.escape fixes proj[1]/env, but the escaped path still goes through glob matching: proj[1] becomes proj[[]1], so glob still lists the directory that contains it and matches the entries itself. That leaves cases that fail with the same ValueError:

    • on a case-insensitive filesystem (macOS, Cygwin), nodeenv --prebuilt PROJ[1]/env when the directory on disk is proj[1]: the match is case-sensitive, so it finds nothing, while the same path without brackets works;
    • when the directory that contains proj[1] can be entered but not listed (mode 0311 or 0711), glob swallows the PermissionError and returns [];
    • node_version is still not escaped, and a version such as 18.0.0+build[1] with a custom mirror passes the version check.

    The env path doesn't need to be in the pattern at all. Python 3.10 is the minimum now, so root_dir can take it:

        src_folder_tpl = glob.escape('node-v%s-' % node_version) + '*'
        src_folder, = glob.glob(src_folder_tpl, root_dir=src_dir)
        copytree(join(src_dir, src_folder), dest, True)

    The - after the version also stops the glob from matching node-v18.1.10-linux-x64 when installing 18.1.1, or a source tree node-v18.1.1 left in src/ (the second case in #443). Both fail now with too many values to unpack. I checked all of these cases on macOS: the current pattern finds no folder or several, this one finds exactly one. If you take the - too, please mention it in the CHANGES entry.

  • The test repeats the is_WIN/is_CYGWIN branching from copy_node_from_prebuilt. The bug doesn't depend on the platform, so patching both to False, as test_download_node_src_tar_keeps_data_filter does, keeps the test short and doesn't tie it to that logic. Of the nine cases, plain, path with spaces, café, proj[ and proj] pass on master as well (a [ without a closing ] is a literal for fnmatch), so only proj[1], proj* and proj? cover #441 and the rest can go. With the - change, a case with node-v18.1.10-... or node-v18.1.1 next to the archive folder would cover it. I tried such tests: they fail on master and pass with the change above.

@ekalinin

Copy link
Copy Markdown
Owner

Please rebase on master.

@tridev-tej
tridev-tej force-pushed the tejesh/fix-prebuilt-path-glob branch from 7c7d74a to 06f9071 Compare October 30, 2026 22:15
@tridev-tej

Copy link
Copy Markdown
Contributor Author

Addressed the requested changes and rebased onto master. Could you take another look?

@ekalinin
ekalinin merged commit e1e016b into ekalinin:master Oct 31, 2026
26 checks passed
@ekalinin ekalinin added the bug label Oct 31, 2026
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.

--prebuilt fails when the environment path contains [

2 participants