gitea.tea/modules
Lunny Xiao 22d43ec9b6
Some checks are pending
goreleaser / goreleaser (push) Waiting to run
goreleaser / release-image (push) Waiting to run
fix(login): avoid panic when parsing auto-discovered SSH keys (#1100)
## Problem

`tea login add` can panic while auto-discovering SSH keys. The interactive login flow calls `regexp.FindStringSubmatch` and immediately indexes `[1]` without checking whether the regex matched. When the selected key display string does not have the expected format, the returned slice is `nil` and tea crashes with:

```
panic: runtime error: index out of range [1] with length 0
```

This is the crash reported in #527.

## Root cause

`regexp.Regexp.FindStringSubmatch` returns `nil` when the input does not match. Indexing that result with `[1]` assumes a match and causes the panic. The same unchecked pattern exists for SSH certificates and plain public keys in `modules/interact/login.go`.

## Changes

- Extract auto-discovered SSH key/certificate display parsing into `parseSSHPubkeySelection`.
- Add a `regexpSubmatch` helper that returns an error when a regex does not match, so login fails with a descriptive error instead of panicking.
- Add table-driven tests for local/agent keys, local/agent certificates, and malformed input.

Fixes #527

---------

Co-authored-by: bircni <bircni@icloud.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/1100
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2026-08-23 19:20:19 +00:00
..
api fix(http): add transport timeouts so tea fails fast on stalled servers (#1020) 2026-06-26 19:59:05 +00:00
auth fix(oauth): don't wait for the browser opener to exit (#1093) 2026-08-16 12:57:47 +00:00
config chore(config): replace authgate SDK with signet (#1081) 2026-08-02 14:38:25 +00:00
context fix(context): clarify the fallback login prompt wording (#1061) 2026-07-26 01:38:10 +00:00
debug add debug mode and update readme (#805) 2025-09-10 19:10:02 +00:00
filelock Move versions/filelocker into dedicated subpackages, and consistent headers in http requests (#888) 2026-02-05 18:05:43 +00:00
git Add reply to code review (#978) 2026-06-26 21:40:31 +00:00
httputil fix(http): add transport timeouts so tea fails fast on stalled servers (#1020) 2026-06-26 19:59:05 +00:00
interact fix(login): avoid panic when parsing auto-discovered SSH keys (#1100) 2026-08-23 19:20:19 +00:00
print fix(labels): add org label for ls and pr (#1017) 2026-06-24 17:46:12 +00:00
task feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
theme fix(theme): don't query the terminal at start-up (#1054) 2026-07-13 04:31:26 +00:00
utils feat(pulls): add --draft to create and --draft/--ready to edit (#1008) 2026-05-31 02:50:32 +00:00
version Move versions/filelocker into dedicated subpackages, and consistent headers in http requests (#888) 2026-02-05 18:05:43 +00:00