Skip to content
Myr

cmd: Fix panic if cmd ends on dash or underscore

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent efbe9b0 · Browse files · 2 files+8 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−0 removed

  • other:+8 added−0 removed

2 files+8 added−0 removed

modified:cobra/cmd/add_test.go+2 added
85 unmodified lines
86 {"cmd______Name", "cmdName"},87 {"cmd------Name", "cmdName"},88 {"cmd______name", "cmdName"},89 {"cmd------name", "cmdName"},90 {"cmdName-----", "cmdName"},91 {"cmdname-", "cmdname"},92 }9394 for _, testCase := range testCases {95 got := validateCmdName(testCase.input)
5 unmodified lines
modified:cobra/cmd/add.go+6 added
75 unmodified lines
76 if output == "" {77 output = source[:i]78 }7980 // If it's last rune and it's dash or underscore,81 // don't add it output and break the loop.82 if i == l-1 {83 break84 }8586 // If next character is dash or underscore,87 // just skip the current character.88 if source[i+1] == '-' || source[i+1] == '_' {89 i++
84 unmodified lines