Merge pull request #91859 from SataQiu/fix-apiserver-20200606

Fix kube-apiserver panic when CRD Kind contains only one letter
This commit is contained in:
Kubernetes Prow Robot 2020-06-06 20:21:45 -07:00 committed by GitHub
commit 22de8fc321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {