fix kube-apiserver panic when CRD Kind contains only one letter
Signed-off-by: SataQiu <1527062125@qq.com> Kubernetes-commit: 2c8c9d02098a975ee3f42c6a6d29579da8502b6d
This commit is contained in:
parent
3f3681bf8c
commit
6b9950ac7e
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue