Repository navigation
Strip OpenSSH-style inline comments from SSHConfig values - #2727
Open
inchang-ing wants to merge 1 commit into
Open
inchang-ing wants to merge 1 commit into
inchang-ing wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2726.
Problem
SSHConfig.parse()keeps trailing comments as part of a config value:lookup("web")["user"]returns'admin # backup', whilessh -F c.conf -G webreports
admin. Quoted values and mid-token#characters must stay literal:"ad # min" # tailshould yieldad # min, andadmin#fragmust remainadmin#frag. Stripping every#would therefore be wrong.Change
Add
SSHConfig._strip_inline_comment()and apply it to the value captured bySETTINGS_REGEX, before the existingHost/Match/keyword handling. Itfollows OpenSSH's
argv_splitcomment handling:#starts a comment only at atoken boundary (start of the value or right after whitespace), never inside
single or double quotes, and never in the middle of a token. Quotes and escaped
characters are otherwise left alone, so the existing quote removal, multi-word
values,
=-style values,IdentityFilelists and%-substitution keep theircurrent behaviour. No control flow is changed: a
Host/Matchline stillswitches context even when its value consists only of a comment.
Verification
tests/test_config.py: trailing comments (including after atab and at end of value), quoted
#, literal mid-token#, values withoutcomments,
Hostlines with comments, and a mixed block with multi-word,quoted and
ProxyCommand/IdentityFilevalues.The six failures are exactly the trailing-comment,
Host-line and quoted-valuecases; the six cases that were already correct still pass.
tests/test_config.py.command pinned by the project's dev dependencies).
black22.12 and localruffproduce only pre-existing findings on untouched lines; the patch addsnone.
sets (one pre-existing Windows-only integration failure), with 202 -> 214
passed, i.e. exactly the 12 new cases.
Limitations
ssh -Gresult quoted in the issue and from OpenSSH'sargv_splitcomment handling.pytest.skip()intests/test_sftp.py(identical before and after this change); an explicit list of test files was used instead to compare failure sets.