fix: tolerate malformed ssh url usernames (#4270)

This commit is contained in:
Neil
2026-05-31 10:25:25 -07:00
committed by GitHub
parent 12da94a906
commit 4e4f21c94d
2 changed files with 17 additions and 1 deletions
@@ -62,6 +62,16 @@ describe('parseSshHostInput', () => {
})
})
it('does not throw on malformed username escapes in invalid ssh URL ports', () => {
expect(parseSshHostInput('ssh://bad%ZZ@example.com:99999/srv/app')).toEqual({
host: 'example.com',
username: 'bad%ZZ',
port: undefined,
invalidPort: true,
configHost: 'example.com'
})
})
it('keeps plain OpenSSH config aliases valid without a username', () => {
expect(parseSshHostInput('prod-box')).toEqual({
host: 'prod-box',
@@ -199,7 +199,13 @@ function decodeSshUrlUsername(value: string): string | undefined {
if (!value) {
return undefined
}
return decodeURIComponent(value)
try {
return decodeURIComponent(value)
} catch {
// Why: malformed pasted SSH URLs should surface validation errors in the
// form, not throw during parsing before the user can fix the input.
return value
}
}
function parseHostAndOptionalPort(input: string): {