Skip to content

fix: Split clone replace flag on first colon and reject empty search - #1031

Open
ethanstoner wants to merge 2 commits into
ankitpokhrel:mainfrom
ethanstoner:fix/clone-replace-colon
Open

ethanstoner wants to merge 2 commits into
ankitpokhrel:mainfrom
ethanstoner:fix/clone-replace-colon

Conversation

@ethanstoner

Copy link
Copy Markdown

Bug

jira issue clone --replace "<search>:<replace>" split the value on every colon and required exactly two pieces. Because of that:

  • Replacement values that contain a colon (URLs, times like 10:30) were rejected with "Invalid replace string" and the replacement was skipped.
  • --replace ":x" got past the check with an empty search string. strings.ReplaceAll(s, "", "x") then put x between every character of the summary and body (the ADF path did the same for each text node).

Root cause

In internal/cmd/issue/clone/clone.go, the replace loop used strings.Split(r, ":") with a len(pieces) != 2 check and never checked for an empty search string.

Change

  • Moved the parsing into a small parseReplace helper. It uses strings.Cut(r, ":"), which is the same as strings.SplitN(r, ":", 2), so the value is split on the first colon only. The replacement can contain colons. The search string can't.
  • An empty search string is now rejected with the existing "Invalid replace string ... Skipping replacement..." message. The message now also shows the bad value and the reason.
  • The --replace flag help now explains the first-colon rule.

Valid <search>:<replace> pairs with no extra colons work the same as before.

Tests

  • Added internal/cmd/issue/clone/clone_test.go, a table-driven test for parseReplace (this package had no tests before). It covers a simple pair, an empty replacement, a replacement with colons (URL with a port, a time), a missing separator, an empty search string and empty input.
  • I ran the new test against the old split logic first. The colon and empty-search cases failed. They pass with the fix.
  • go test ./..., go vet ./... and gofmt -l pass. golangci-lint run ./... reports 0 issues.

Fixes #1029

Generated with Claude Code on behalf of @ethanstoner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issue clone --replace splits on every colon and accepts empty find string (rejects URLs, corrupts body)

1 participant