Skip to content

feat: enhance robustness of --confallhosts parsing#199

Open
joshsleeper wants to merge 1 commit intodanielrobbins:masterfrom
joshsleeper:jsleeper/feat/confallhosts_robustness
Open

feat: enhance robustness of --confallhosts parsing#199
joshsleeper wants to merge 1 commit intodanielrobbins:masterfrom
joshsleeper:jsleeper/feat/confallhosts_robustness

Conversation

@joshsleeper
Copy link

@joshsleeper joshsleeper commented Feb 15, 2026

alternate to #197
closes #198

changes

  • enhance robustness of --confallhosts parsing
  • it should now gracefully handle...
    • the very last config line if it doesn't end with a newline
      • || [ -n "$line"] was new to me, I never realized that read -r would drop the final line if it didn't end with a newline
    • leading whitespace
    • commented lines
    • quoted arguments
    • known homedir shorthands

validation

I churned on this locally by piping in this file, which includes examples for each resolved issue I believe

  • leading space or tab that should be stripped
  • leading tab
  • commented lines that should be ignored, both with and without whitespace between # and the keyword
  • unquoted and quoted examples of absolute path and all three homedir shorthands
#IdentityFile /home/user/.ssh/commented
 #IdentityFile /home/user/.ssh/commented
	#IdentityFile /home/user/.ssh/commented
# IdentityFile /home/user/.ssh/commented
 # IdentityFile /home/user/.ssh/commented
	# IdentityFile /home/user/.ssh/commented
IdentityFile /home/<REAL_USER_PLACEHOLDER>/.ssh/codeberg
IdentityFile "/home/<REAL_USER_PLACEHOLDER>/.ssh/codeberg"
IdentityFile ~/.ssh/codeberg
IdentityFile "~/.ssh/codeberg"
IdentityFile %d/.ssh/codeberg
IdentityFile "%d/.ssh/codeberg"
IdentityFile ${HOME}/.ssh/codeberg
IdentityFile "${HOME}/.ssh/codeberg"

context

I ran into this again recently while setting up a new system and remembered that I'd encountered the lack of ~ parsing back when --confallhosts first shipped but I failed to actually report it 🥲.

found #198 and #197 when looking to see if anyone had tried to fix it yet, and reviewing the PR got me thinking about the problem space and all the various little ways ssh_config parsing is "fun", several of which I mention in my issue comment here: #198 (comment)

after doing the reading and writing the explanation I felt silly and realized I should probably just open a PR that covers all the edge cases I'd brought up.

it should now gracefully handle leading whitespace, commented lines, quoted arguments, and known homedir shorthands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tildes are not expanded from .ssh/config

1 participant