Skip to content

Commit

Permalink
cmd/util: avoid an empty string to be parsed
Browse files Browse the repository at this point in the history
An additional empty string was being added in the array of "branchArgs" to
later be processed as a valid branch/remote information by the argument
parses. It wasn't an issue before because a "err" return value was being
ignored somewhere else within the parses, but the commit 69ae19e ("cmd:
fix return value checks and statements") changed it and the error finally
was cought.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Jun 15, 2021
1 parent 5f7d2aa commit ecd57aa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ func parseArgsWithGitBranchMR(args []string) (string, int64, error) {
return s, i, nil
}

// filterCommentArg separate the case where a command can have both the
// remote and "<mrID>:<commentID>" at the same time.
func filterCommentArg(args []string) (int, []string, error) {
branchArgs := []string{}
idString := ""
Expand All @@ -359,16 +361,18 @@ func filterCommentArg(args []string) (int, []string, error) {
} else {
idString = args[0]
}
} else if len(args) > 1 {
} else if len(args) == 2 {
branchArgs = append(branchArgs, args[0])
idString = args[1]
} else {
return 0, branchArgs, fmt.Errorf("unsupported number of arguments")
}

if strings.Contains(idString, ":") {
ps := strings.Split(idString, ":")
branchArgs = append(branchArgs, ps[0])
idString = ps[1]
} else {
} else if idString != "" {
branchArgs = append(branchArgs, idString)
idString = ""
}
Expand Down

0 comments on commit ecd57aa

Please sign in to comment.