fix: make SSH config directive matching case-insensitive

resolve_ssh_alias() used a case statement that only matched
'HostName' (capital N), but OpenSSH treats config directives
as case-insensitive: 'Hostname', 'HostName', 'HOSTNAME' and
'hostname' are all equivalent. A config like

    Host retailpos-hites-qa
        Hostname 10.60.16.35
        User retailpos
        IdentityFile ~/.ssh/retailpos-key

produced 'has no HostName' even though one was present.

Enable 'shopt -s nocasematch' around the parsing loop so the
case branches match any casing. nocasematch was chosen over
${var,,} because the latter requires bash 4+, and macOS still
ships bash 3.2.57 as /bin/bash.

The 'Host' pattern itself remains case-sensitive, matching
ssh's own behavior.

Verified against: tabbed/spaced/mixed indentation, lowercase,
uppercase, mixed-casing directives, the user's exact config,
and the previous regression cases.
This commit is contained in:
2026-09-09 11:26:35 -03:00
parent 4d55c8b8bb
commit 6740e4e398
+4
View File
@@ -134,6 +134,9 @@ resolve_ssh_alias() {
local -a patterns local -a patterns
# Force whitespace-aware splitting (the script's global IFS excludes spaces). # Force whitespace-aware splitting (the script's global IFS excludes spaces).
local IFS=$' \t\n' local IFS=$' \t\n'
# SSH config directives are case-insensitive (HostName == Hostname == HOSTNAME).
# nocasematch is supported in bash 3.2 (unlike ${var,,} which needs 4+).
shopt -s nocasematch
while read -r line || [[ -n "$line" ]]; do while read -r line || [[ -n "$line" ]]; do
# First whitespace-separated token (tabs and spaces collapse uniformly). # First whitespace-separated token (tabs and spaces collapse uniformly).
read -r first _ <<< "$line" read -r first _ <<< "$line"
@@ -163,6 +166,7 @@ resolve_ssh_alias() {
esac esac
fi fi
done < "$config" done < "$config"
shopt -u nocasematch
(( in_block )) \ (( in_block )) \
|| die "No matching Host entry in $config for alias '$alias'. Use user@host[:port] or check ~/.ssh/config." || die "No matching Host entry in $config for alias '$alias'. Use user@host[:port] or check ~/.ssh/config."