Fix tilde expand for Windows paths with backslashes (#768)

* add backslash support for Windows paths

* add pester tests for tilde_expand

* fix typo
This commit is contained in:
Tess Gauthier 2025-01-06 14:11:58 -05:00 committed by GitHub
parent 0c3137f621
commit cdcc8d34d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 26 deletions

9
misc.c
View File

@ -1261,6 +1261,15 @@ tilde_expand(const char *filename, uid_t uid, char **retp)
path = NULL; /* ~/ */
else
path = copy; /* ~/path */
#ifdef WINDOWS
// also need to account for backward slashes on Windows
} else if (*copy == '\\') {
copy += strspn(copy, "\\");
if (*copy == '\0')
path = NULL; /* ~\ */
else
path = copy; /* ~\path */
#endif /* WINDOWS */
} else {
user = copy;
if ((path = strchr(copy, '/')) != NULL) {

View File

@ -27,7 +27,7 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($ssouser, $rights, "ContainerInherit,Objectinherit", "None", "Allow")
$acl.SetAccessRule($accessRule)
Set-Acl -Path $testDir -AclObject $acl
#skip on ps 2 becase non-interactive cmd require a ENTER before it returns on ps2
#skip on ps 2 because non-interactive cmd require a ENTER before it returns on ps2
$skip = $IsWindows -and ($PSVersionTable.PSVersion.Major -le 2)
<#$testData = @(
@ -349,6 +349,18 @@ Describe "E2E scenarios for ssh client" -Tags "CI" {
$logFile | Should Contain "[::1]"
}
It "$tC.$tI - tilde expand for path with forward slash" {
$o = ssh -v -i ~/test/key/path -E $logFile test_target echo 1234
$o | Should Be "1234"
$logFile | Should Not Contain "tilde_expand: No such user"
}
It "$tC.$tI - tilde expand for path with backslash" {
$o = ssh -v -i ~\test\key\path -E $logFile test_target echo 1234
$o | Should Be "1234"
$logFile | Should Not Contain "tilde_expand: No such user"
}
It "$tC.$tI - auto populate known hosts" {
$kh = Join-Path $testDir "$tC.$tI.known_hosts"