MM-41909: Allow 1 char channel name (#19845)
* [ MM-41909 ] Allow 1 character channel names Change minimal length to 1 * [ MM-41909 ] Fix localization string * [ MM-41909 ] Modify condition to allow 1 char channel name * [ MM-41909 ] fix formatting * [MM-41909] Linting fix * [MM-41909] Fix regex * [MM-41909] Localization update * [MM-41909] Attempt to fix test Co-authored-by: Kevin Jiang <> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
053e92a683
Коммит
5cb31a114a
@@ -28,7 +28,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
|
|||||||
// Table Test for basic cases. Blank text in response indicates success
|
// Table Test for basic cases. Blank text in response indicates success
|
||||||
for msg, expected := range map[string]string{
|
for msg, expected := range map[string]string{
|
||||||
"": "api.command_channel_rename.message.app_error",
|
"": "api.command_channel_rename.message.app_error",
|
||||||
"o": "api.command_channel_rename.too_short.app_error",
|
"o": "",
|
||||||
"joram": "",
|
"joram": "",
|
||||||
"More than 22 chars but less than 64": "",
|
"More than 22 chars but less than 64": "",
|
||||||
strings.Repeat("12345", 13): "api.command_channel_rename.too_long.app_error",
|
strings.Repeat("12345", 13): "api.command_channel_rename.too_long.app_error",
|
||||||
|
|||||||
@@ -7688,8 +7688,8 @@
|
|||||||
"translation": "Invalid username."
|
"translation": "Invalid username."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.channel.is_valid.2_or_more.app_error",
|
"id": "model.channel.is_valid.1_or_more.app_error",
|
||||||
"translation": "Name must be 2 or more lowercase alphanumeric characters."
|
"translation": "Name must be 1 or more lowercase alphanumeric character."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.channel.is_valid.create_at.app_error",
|
"id": "model.channel.is_valid.create_at.app_error",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const (
|
|||||||
ChannelGroupMinUsers = 3
|
ChannelGroupMinUsers = 3
|
||||||
DefaultChannelName = "town-square"
|
DefaultChannelName = "town-square"
|
||||||
ChannelDisplayNameMaxRunes = 64
|
ChannelDisplayNameMaxRunes = 64
|
||||||
ChannelNameMinLength = 2
|
ChannelNameMinLength = 1
|
||||||
ChannelNameMaxLength = 64
|
ChannelNameMaxLength = 64
|
||||||
ChannelHeaderMaxRunes = 1024
|
ChannelHeaderMaxRunes = 1024
|
||||||
ChannelPurposeMaxRunes = 250
|
ChannelPurposeMaxRunes = 250
|
||||||
@@ -216,7 +216,7 @@ func (o *Channel) IsValid() *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !IsValidChannelIdentifier(o.Name) {
|
if !IsValidChannelIdentifier(o.Name) {
|
||||||
return NewAppError("Channel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
return NewAppError("Channel.IsValid", "model.channel.is_valid.1_or_more.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(o.Type == ChannelTypeOpen || o.Type == ChannelTypePrivate || o.Type == ChannelTypeDirect || o.Type == ChannelTypeGroup) {
|
if !(o.Type == ChannelTypeOpen || o.Type == ChannelTypePrivate || o.Type == ChannelTypeDirect || o.Type == ChannelTypeGroup) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (sc *SharedChannel) IsValid() *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !IsValidChannelIdentifier(sc.ShareName) {
|
if !IsValidChannelIdentifier(sc.ShareName) {
|
||||||
return NewAppError("SharedChannel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+sc.ChannelId, http.StatusBadRequest)
|
return NewAppError("SharedChannel.IsValid", "model.channel.is_valid.1_or_more.app_error", nil, "id="+sc.ChannelId, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if utf8.RuneCountInString(sc.ShareHeader) > ChannelHeaderMaxRunes {
|
if utf8.RuneCountInString(sc.ShareHeader) > ChannelHeaderMaxRunes {
|
||||||
|
|||||||
@@ -510,21 +510,13 @@ var reservedName = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsValidChannelIdentifier(s string) bool {
|
func IsValidChannelIdentifier(s string) bool {
|
||||||
|
return validSimpleAlphaNum.MatchString(s) && len(s) >= ChannelNameMinLength
|
||||||
if !IsValidAlphaNumHyphenUnderscore(s, true) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(s) < ChannelNameMinLength {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
validAlphaNum = regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
|
validAlphaNum = regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
|
||||||
validAlphaNumHyphenUnderscore = regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
|
validAlphaNumHyphenUnderscore = regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
|
||||||
|
validSimpleAlphaNum = regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]*$`)
|
||||||
validSimpleAlphaNumHyphenUnderscore = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`)
|
validSimpleAlphaNumHyphenUnderscore = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`)
|
||||||
validSimpleAlphaNumHyphenUnderscorePlus = regexp.MustCompile(`^[a-zA-Z0-9+_-]+$`)
|
validSimpleAlphaNumHyphenUnderscorePlus = regexp.MustCompile(`^[a-zA-Z0-9+_-]+$`)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -862,6 +862,55 @@ func TestSanitizeUnicode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsValidChannelIdentifier(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Description string
|
||||||
|
Input string
|
||||||
|
Expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Description: "less than min length",
|
||||||
|
Input: "",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "single alphabetical char",
|
||||||
|
Input: "a",
|
||||||
|
Expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "single underscore",
|
||||||
|
Input: "_",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "single hyphen",
|
||||||
|
Input: "-",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "empty string",
|
||||||
|
Input: " ",
|
||||||
|
Expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "multiple with hyphen",
|
||||||
|
Input: "a-a",
|
||||||
|
Expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: "multiple with hyphen",
|
||||||
|
Input: "a_a",
|
||||||
|
Expected: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
actual := IsValidChannelIdentifier(tc.Input)
|
||||||
|
require.Equalf(t, actual, tc.Expected, "case: '%v'\tshould returned: %#v", tc.Input, tc.Expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIsValidHTTPURL(t *testing.T) {
|
func TestIsValidHTTPURL(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user