mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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:
commit
22de8fc321
@ -1070,7 +1070,7 @@ func splitSubresource(path string) (string, string, error) {
|
|||||||
|
|
||||||
// GetArticleForNoun returns the article needed for the given noun.
|
// GetArticleForNoun returns the article needed for the given noun.
|
||||||
func GetArticleForNoun(noun string, padding string) string {
|
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.
|
// Plurals don't have an article.
|
||||||
// Don't catch words like class
|
// Don't catch words like class
|
||||||
return fmt.Sprintf("%v", padding)
|
return fmt.Sprintf("%v", padding)
|
||||||
|
@ -80,6 +80,16 @@ func TestGetArticleForNoun(t *testing.T) {
|
|||||||
padding: " ",
|
padding: " ",
|
||||||
want: " a ",
|
want: " a ",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
noun: "S",
|
||||||
|
padding: " ",
|
||||||
|
want: " a ",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
noun: "O",
|
||||||
|
padding: " ",
|
||||||
|
want: " an ",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := GetArticleForNoun(tt.noun, tt.padding); got != tt.want {
|
if got := GetArticleForNoun(tt.noun, tt.padding); got != tt.want {
|
||||||
|
Loading…
Reference in New Issue
Block a user