Not allow '$' in collection/partition/field name (#19082)

Signed-off-by: yhmo <yihua.mo@zilliz.com>

Signed-off-by: yhmo <yihua.mo@zilliz.com>
pull/19044/head
groot 2022-09-08 10:16:34 +08:00 committed by GitHub
parent 60f427dad2
commit ebc263f440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -104,8 +104,8 @@ func validateCollectionNameOrAlias(entity, entityType string) error {
for i := 1; i < len(entity); i++ {
c := entity[i]
if c != '_' && c != '$' && !isAlpha(c) && !isNumber(c) {
msg := invalidMsg + fmt.Sprintf("Collection %s can only contain numbers, letters, dollars and underscores.", entityType)
if c != '_' && !isAlpha(c) && !isNumber(c) {
msg := invalidMsg + fmt.Sprintf("Collection %s can only contain numbers, letters and underscores.", entityType)
return errors.New(msg)
}
}
@ -131,7 +131,7 @@ func validatePartitionTag(partitionTag string, strictCheck bool) error {
}
if int64(len(partitionTag)) > Params.ProxyCfg.MaxNameLength {
msg := invalidMsg + "The length of a partition tag must be less than " +
msg := invalidMsg + "The length of a partition name must be less than " +
strconv.FormatInt(Params.ProxyCfg.MaxNameLength, 10) + " characters."
return errors.New(msg)
}
@ -139,15 +139,15 @@ func validatePartitionTag(partitionTag string, strictCheck bool) error {
if strictCheck {
firstChar := partitionTag[0]
if firstChar != '_' && !isAlpha(firstChar) && !isNumber(firstChar) {
msg := invalidMsg + "The first character of a partition tag must be an underscore or letter."
msg := invalidMsg + "The first character of a partition name must be an underscore or letter."
return errors.New(msg)
}
tagSize := len(partitionTag)
for i := 1; i < tagSize; i++ {
c := partitionTag[i]
if c != '_' && c != '$' && !isAlpha(c) && !isNumber(c) {
msg := invalidMsg + "Partition tag can only contain numbers, letters, dollars and underscores."
if c != '_' && !isAlpha(c) && !isNumber(c) {
msg := invalidMsg + "Partition name can only contain numbers, letters and underscores."
return errors.New(msg)
}
}

View File

@ -38,7 +38,7 @@ import (
func TestValidateCollectionName(t *testing.T) {
assert.Nil(t, validateCollectionName("abc"))
assert.Nil(t, validateCollectionName("_123abc"))
assert.Nil(t, validateCollectionName("abc123_$"))
assert.Nil(t, validateCollectionName("abc123_"))
longName := make([]byte, 256)
for i := 0; i < len(longName); i++ {
@ -47,6 +47,7 @@ func TestValidateCollectionName(t *testing.T) {
invalidNames := []string{
"123abc",
"$abc",
"abc$",
"_12 ac",
" ",
"",
@ -65,7 +66,7 @@ func TestValidatePartitionTag(t *testing.T) {
assert.Nil(t, validatePartitionTag("abc", true))
assert.Nil(t, validatePartitionTag("123abc", true))
assert.Nil(t, validatePartitionTag("_123abc", true))
assert.Nil(t, validatePartitionTag("abc123_$", true))
assert.Nil(t, validatePartitionTag("abc123_", true))
longName := make([]byte, 256)
for i := 0; i < len(longName); i++ {
@ -73,6 +74,7 @@ func TestValidatePartitionTag(t *testing.T) {
}
invalidNames := []string{
"$abc",
"abc$",
"_12 ac",
" ",
"",
@ -91,6 +93,7 @@ func TestValidatePartitionTag(t *testing.T) {
func TestValidateFieldName(t *testing.T) {
assert.Nil(t, validateFieldName("abc"))
assert.Nil(t, validateFieldName("_123abc"))
assert.Nil(t, validateFieldName("abc123_"))
longName := make([]byte, 256)
for i := 0; i < len(longName); i++ {
@ -99,6 +102,7 @@ func TestValidateFieldName(t *testing.T) {
invalidNames := []string{
"123abc",
"$abc",
"abc$",
"_12 ac",
" ",
"",