mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Escape installer PATH entries for shell metacharacters (#62055)
## Why Installation directories containing shell metacharacters can be interpreted incorrectly in shell profiles and the printed launch command. ## What changed Escape installation directories in the generated `PATH` export and reuse that export in the current-terminal instructions. Preserve the escape sequences when rewriting an existing profile block by passing the line through the `awk` environment. ## Testing Add a regression test that installs into directories containing shell metacharacters, verifies `codex` lookup after adding and updating the profile, and executes the printed launch command. GitOrigin-RevId: b6c6044382128c97dfb503516f5eeaa934c85bbb
This commit is contained in:
+17
-38
@@ -611,7 +611,9 @@ add_to_path() {
|
||||
path_profile="$profile"
|
||||
begin_marker="# >>> Codex installer >>>"
|
||||
end_marker="# <<< Codex installer <<<"
|
||||
path_line="export PATH=\"$BIN_DIR:\$PATH\""
|
||||
# Escape the directory for double quotes. Quote ! separately for interactive shells.
|
||||
path_prefix=$(printf '%s:\n' "$BIN_DIR" | LC_ALL=C sed 's/[\\"$`]/\\&/g; s/!/"\\!"/g')
|
||||
path_line="export PATH=\"$path_prefix\$PATH\""
|
||||
|
||||
if [ -f "$profile" ] && grep -F "$begin_marker" "$profile" >/dev/null 2>&1; then
|
||||
if grep -F "$path_line" "$profile" >/dev/null 2>&1; then
|
||||
@@ -650,7 +652,7 @@ rewrite_path_block() {
|
||||
path_line="$4"
|
||||
tmp_profile="$tmp_dir/profile.$$.tmp"
|
||||
|
||||
awk -v begin="$begin_marker" -v end="$end_marker" -v line="$path_line" '
|
||||
CODEX_PATH_LINE="$path_line" awk -v begin="$begin_marker" -v end="$end_marker" '
|
||||
BEGIN {
|
||||
in_block = 0
|
||||
replaced = 0
|
||||
@@ -658,7 +660,7 @@ rewrite_path_block() {
|
||||
$0 == begin {
|
||||
if (!replaced) {
|
||||
print begin
|
||||
print line
|
||||
print ENVIRON["CODEX_PATH_LINE"]
|
||||
print end
|
||||
replaced = 1
|
||||
}
|
||||
@@ -1038,26 +1040,18 @@ prompt_yes_no() {
|
||||
}
|
||||
|
||||
print_launch_instructions() {
|
||||
if [ "$path_action" = "already" ]; then
|
||||
step "$BIN_DIR is already on PATH"
|
||||
step "Current terminal: codex"
|
||||
else
|
||||
step "Current terminal: $path_line && codex"
|
||||
fi
|
||||
step "Future terminals: open a new terminal and run: codex"
|
||||
|
||||
case "$path_action" in
|
||||
added)
|
||||
step "Current terminal: export PATH=\"$BIN_DIR:\$PATH\" && codex"
|
||||
step "Future terminals: open a new terminal and run: codex"
|
||||
step "PATH was added to $path_profile"
|
||||
;;
|
||||
updated)
|
||||
step "Current terminal: export PATH=\"$BIN_DIR:\$PATH\" && codex"
|
||||
step "Future terminals: open a new terminal and run: codex"
|
||||
step "PATH was updated in $path_profile"
|
||||
;;
|
||||
configured)
|
||||
step "Current terminal: export PATH=\"$BIN_DIR:\$PATH\" && codex"
|
||||
step "Future terminals: open a new terminal and run: codex"
|
||||
step "PATH is already configured in $path_profile"
|
||||
;;
|
||||
*)
|
||||
step "Current terminal: codex"
|
||||
step "Future terminals: open a new terminal and run: codex"
|
||||
;;
|
||||
added) step "PATH was added to $path_profile" ;;
|
||||
updated) step "PATH was updated in $path_profile" ;;
|
||||
configured) step "PATH is already configured in $path_profile" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -1479,22 +1473,7 @@ if ! prune_standalone_releases; then
|
||||
fi
|
||||
release_install_lock
|
||||
handle_conflicting_install
|
||||
|
||||
case "$path_action" in
|
||||
added)
|
||||
print_launch_instructions
|
||||
;;
|
||||
updated)
|
||||
print_launch_instructions
|
||||
;;
|
||||
configured)
|
||||
print_launch_instructions
|
||||
;;
|
||||
*)
|
||||
step "$BIN_DIR is already on PATH"
|
||||
print_launch_instructions
|
||||
;;
|
||||
esac
|
||||
print_launch_instructions
|
||||
|
||||
printf 'Codex CLI %s installed successfully.\n' "$resolved_version"
|
||||
maybe_launch_codex_now
|
||||
|
||||
Reference in New Issue
Block a user