fix: tolerate malformed ssh url usernames (#4270)
This commit is contained in:
@@ -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): {
|
||||
|
||||
Reference in New Issue
Block a user