fix kube-apiserver panic when CRD Kind contains only one letter

Signed-off-by: SataQiu <1527062125@qq.com>
This commit is contained in:
SataQiu 2020-06-06 23:01:35 +08:00
parent 3a8d130fdf
commit 2c8c9d0209
2 changed files with 11 additions and 1 deletions

View File

@ -1070,7 +1070,7 @@ func splitSubresource(path string) (string, string, error) {
// GetArticleForNoun returns the article needed for the given noun.
func GetArticleForNoun(noun string, padding string) string {
if noun[len(noun)-2:] != "ss" && noun[len(noun)-1:] == "s" {
if !strings.HasSuffix(noun, "ss") && strings.HasSuffix(noun, "s") {
// Plurals don't have an article.
// Don't catch words like class
return fmt.Sprintf("%v", padding)

View File

@ -80,6 +80,16 @@ func TestGetArticleForNoun(t *testing.T) {
padding: " ",
want: " a ",
},
{
noun: "S",
padding: " ",
want: " a ",
},
{
noun: "O",
padding: " ",
want: " an ",
},
}
for _, tt := range tests {
if got := GetArticleForNoun(tt.noun, tt.padding); got != tt.want {