gitea.tea/modules/task
Ross Golder c48e2af033
fix(flags): drop empty/whitespace entries when parsing CSV flags
Comma-separated flags (`--assignees`, `--labels`, `--add/remove-labels`,
`--add/remove-reviewers`, `--events`, login `--scopes`) silently accepted
stray commas and whitespace, producing values like `[""]` for empty input
or `["alice", "", "bob"]` for `--assignees=alice,,bob`. Those blanks
were then forwarded to the Gitea SDK, where they either triggered obscure
server errors or silently mutated state in unexpected ways.

Root cause: a mix of `strings.Split(s, ",")` and ad-hoc trim loops, none
of which rejected empty segments.

Introduce `modules/utils.SplitCSV` as the single parser for all CSV flag
values. It:

- returns `nil` for an empty or whitespace-only input (so callers can use
  `len(x) == 0` to mean "not set", and `cmd.IsSet("...")` keeps
  working),
- drops empty and whitespace-only segments anywhere in the input,
- otherwise trims surrounding whitespace from each remaining segment.

`cmd/flags.SplitCSV` is re-exported from `cmd/flags/csvflag.go` so
existing call sites read `flags.SplitCSV` without depending on a leaf
package that `modules/task` already imports them.

Convert the remaining raw `strings.Split(..., ",")` sites:

- `cmd/flags/issue_pr.go` (issue/pr --assignees, --labels and the
  set/add/remove variants)
- `cmd/pulls/edit.go` (`--add-reviewers`, `--remove-reviewers`)
- `cmd/webhooks/create.go`, `cmd/webhooks/update.go` (`--events`)
- `modules/task/login_create.go` (login `--scopes`)

Drop the now-unused `"strings"` imports from the three cmd/* files.

Tests:

- `modules/utils/splitcsv_test.go` — table-driven coverage for empty,
  whitespace-only, leading/trailing commas, internal empty segments,
  surrounding whitespace, and re-imported identity with `flags.SplitCSV`.
- `cmd/flags/csvflag_test.go` — `GetValues` happy path, error path,
  empty entry drop, and AvailableFields variants.
- `cmd/flags/issue_pr_test.go` — regression test for
  `GetIssuePREditFlags` proving `SetAssignees/AddAssignees/...`
  produce `nil` (not `[""]`) for empty input and trimmed slices for
  mixed inputs.
2026-09-10 17:31:08 +07:00
..
assignees.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
issue_create.go Make tea issues create honor --output json (#1114) 2026-09-10 04:29:39 +00:00
issue_edit.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
labels.go fix(labels): add org label for ls and pr (#1017) 2026-06-24 17:46:12 +00:00
labels_export.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_create.go fix(flags): drop empty/whitespace entries when parsing CSV flags 2026-09-10 17:31:08 +07:00
login_create_test.go Skip token uniqueness check when using SSH authentication (#898) 2026-02-19 15:19:45 +00:00
login_httpsign.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_ssh.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
login_status.go feat(login): add status command (#1087) (#1105) 2026-08-28 23:55:13 +00:00
login_status_test.go feat(login): add status command (#1087) (#1105) 2026-08-28 23:55:13 +00:00
milestone_create.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_checkout.go Add reply to code review (#978) 2026-06-26 21:40:31 +00:00
pull_clean.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_create.go Make tea pulls create honor --output json (#1111) 2026-09-08 19:20:40 +00:00
pull_create_test.go spdx (#581) 2023-09-08 01:40:02 +00:00
pull_edit.go feat(assignees): add set, add, and remove assignees APIs (#1045) 2026-07-18 00:20:03 +00:00
pull_merge.go fix(pulls): report the real reason when a merge is refused (#1107) 2026-09-09 19:15:46 +00:00
pull_merge_test.go fix(pulls): report the real reason when a merge is refused (#1107) 2026-09-09 19:15:46 +00:00
pull_review.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
pull_review_comment.go Add reply to code review (#978) 2026-06-26 21:40:31 +00:00
repo_clone.go Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006) 2026-05-26 04:51:09 +00:00
wiki.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00
wiki_test.go feat: add wiki CLI commands (#998) 2026-05-26 21:14:47 +00:00