fix: Split clone replace flag on first colon and reject empty search - #1031
Open
ethanstoner wants to merge 2 commits into
Open
ethanstoner wants to merge 2 commits into
ethanstoner wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
jira issue clone --replace "<search>:<replace>"split the value on every colon and required exactly two pieces. Because of that: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 putxbetween 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 usedstrings.Split(r, ":")with alen(pieces) != 2check and never checked for an empty search string.Change
parseReplacehelper. It usesstrings.Cut(r, ":"), which is the same asstrings.SplitN(r, ":", 2), so the value is split on the first colon only. The replacement can contain colons. The search string can't.--replaceflag help now explains the first-colon rule.Valid
<search>:<replace>pairs with no extra colons work the same as before.Tests
internal/cmd/issue/clone/clone_test.go, a table-driven test forparseReplace(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.go test ./...,go vet ./...andgofmt -lpass.golangci-lint run ./...reports 0 issues.Fixes #1029
Generated with Claude Code on behalf of @ethanstoner.