Skip to content

gh-159819: Fix python-config.sh for installation paths containing spaces - #159820

Merged
itamaro merged 6 commits into
python:mainfrom
itamaro:fix-python-config-spaces
Oct 22, 2026
Merged

itamaro merged 6 commits into
python:mainfrom
itamaro:fix-python-config-spaces

Conversation

@itamaro

@itamaro itamaro commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

The shell python-config located its own prefix with unquoted command
substitutions, so any whitespace in the installation path made it print an
empty --prefix and -I/include/...-style paths while exiting 0.

  • Quote the substitutions and the argument loop (POSIX sh, no bashisms).
  • Exit 1 with a message when the script's directory cannot be resolved,
    instead of silently printing empty paths.
  • Replace sed "s#$prefix#$prefix_real#" with a relocate helper using
    parameter expansion, so #, &, \ and regex metacharacters in either
    prefix are handled literally. Same first-occurrence semantics.
  • Add test_python_config_sh_prefix_with_spaces: runs the
    generated script from …/path with spaces/bin/ and checks --prefix,
    --exec-prefix, --includes and empty stderr

Written with assistance from Claude Code Fable 5.1

…ng spaces

The shell variant of python-config located its own installation
prefix with unquoted command substitutions, so a prefix containing
whitespace was word-split: the script printed empty --prefix and
--exec-prefix values and bogus --includes/--ldflags paths while still
exiting 0.  Quote the substitutions, quote the argument loop, and exit
with status 1 when the prefix cannot be determined.
Replace the configured prefix with the installed one using POSIX
parameter expansion instead of sed, so that a prefix containing '#',
'&', a backslash or a regular expression metacharacter is handled
literally.
@itamaro
itamaro requested a review from FFY00 as a code owner October 20, 2026 00:14
@itamaro itamaro added build The build process and cross-build needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
@python-cla-bot

python-cla-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@itamaro
itamaro marked this pull request as ready for review October 20, 2026 00:18
Comment thread Misc/python-config.sh.in Outdated
Comment thread Lib/test/test_sysconfig.py Outdated
dash's echo interprets backslash escapes even in quoted arguments, so a
path containing "\c" was truncated. Print every value with printf '%s\n'.

Test "#", "&" and "\" in the install path and in the configured prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itamaro
itamaro merged commit 3e13407 into python:main Oct 22, 2026
53 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @itamaro for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @itamaro, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 3e134077631fec203e4cdcb44133176d5abbea19 3.14

@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160184 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
itamaro added a commit that referenced this pull request Oct 22, 2026
…ing spaces (GH-159820) (#160184)

gh-159819: Fix python-config.sh for installation paths containing spaces (GH-159820)

The shell `python-config` located its own prefix with unquoted command
substitutions, so any whitespace in the installation path made it print an
empty `--prefix` and `-I/include/...`-style paths while exiting 0.

- Quote the substitutions and the argument loop (POSIX `sh`, no bashisms).
- Exit 1 with a message when the script's directory cannot be resolved,
  instead of silently printing empty paths.
- Replace `sed "s#$prefix#$prefix_real#"` with a `relocate` helper using
  parameter expansion, so `#`, `&`, `\` and regex metacharacters in either
  prefix are handled literally. Same first-occurrence semantics.
- Add `test_python_config_sh_prefix_with_spaces`: runs the
  generated script from `…/path with spaces/bin/` and checks `--prefix`,
  `--exec-prefix`, `--includes` and empty stderr
(cherry picked from commit 3e13407)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160240 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
itamaro added a commit that referenced this pull request Oct 22, 2026
…ing spaces (GH-159820) (#160240)

The shell `python-config` located its own prefix with unquoted command
substitutions, so any whitespace in the installation path made it print an
empty `--prefix` and `-I/include/...`-style paths while exiting 0.

- Quote the substitutions and the argument loop (POSIX `sh`, no bashisms).
- Exit 1 with a message when the script's directory cannot be resolved,
  instead of silently printing empty paths.
- Replace `sed "s#$prefix#$prefix_real#"` with a `relocate` helper using
  parameter expansion, so `#`, `&`, `\` and regex metacharacters in either
  prefix are handled literally. Same first-occurrence semantics.
- Add `test_python_config_sh_prefix_with_spaces`: runs the
  generated script from `…/path with spaces/bin/` and checks `--prefix`,
  `--exec-prefix`, `--includes` and empty stderr

(cherry picked from commit 3e13407)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build The build process and cross-build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants