diff --git a/integration/basic_test.go b/integration/basic_test.go index c13197c81515..741b92eff31c 100644 --- a/integration/basic_test.go +++ b/integration/basic_test.go @@ -297,7 +297,7 @@ func TestCollectionName(t *testing.T) { t.Parallel() - t.Run("Err", func(t *testing.T) { + t.Run("All", func(t *testing.T) { ctx, collection := setup.Setup(t) collectionName300 := strings.Repeat("aB", 150) @@ -312,11 +312,11 @@ func TestCollectionName(t *testing.T) { Name: "InvalidNamespace", Code: 73, Message: fmt.Sprintf( - "Fully qualified namespace is too long. Namespace: testcollectionname_err.%s Max: 255", + "Fully qualified namespace is too long. Namespace: testcollectionname_all.%s Max: 255", collectionName300, ), }, - alt: fmt.Sprintf("Invalid collection name: 'testcollectionname_err.%s'", collectionName300), + alt: fmt.Sprintf("Invalid collection name: 'testcollectionname_all.%s'", collectionName300), }, "WithADollarSign": { collection: "collection_name_with_a-$", @@ -325,16 +325,22 @@ func TestCollectionName(t *testing.T) { Code: 73, Message: `Invalid collection name: collection_name_with_a-$`, }, - alt: `Invalid collection name: 'testcollectionname_err.collection_name_with_a-$'`, + alt: `Invalid collection name: 'testcollectionname_all.collection_name_with_a-$'`, + }, + "WithADash": { + collection: "collection_name_with_a-", + }, + "WithADashAtBeginning": { + collection: "-collection_name", }, "Empty": { collection: "", err: &mongo.CommandError{ Name: "InvalidNamespace", Code: 73, - Message: "Invalid namespace specified 'testcollectionname_err.'", + Message: "Invalid namespace specified 'testcollectionname_all.'", }, - alt: "Invalid collection name: 'testcollectionname_err.'", + alt: "Invalid collection name: 'testcollectionname_all.'", }, } @@ -342,12 +348,16 @@ func TestCollectionName(t *testing.T) { name, tc := name, tc t.Run(name, func(t *testing.T) { err := collection.Database().CreateCollection(ctx, tc.collection) - AssertEqualAltError(t, *tc.err, tc.alt, err) + if tc.err != nil { + AssertEqualAltError(t, *tc.err, tc.alt, err) + return + } + assert.NoError(t, err) }) } }) - t.Run("Ok", func(t *testing.T) { + t.Run("LongName", func(t *testing.T) { ctx, collection := setup.Setup(t) longCollectionName := strings.Repeat("a", 100) diff --git a/internal/handlers/pg/pgdb/collections.go b/internal/handlers/pg/pgdb/collections.go index a817a21ff4bd..03ae99560cff 100644 --- a/internal/handlers/pg/pgdb/collections.go +++ b/internal/handlers/pg/pgdb/collections.go @@ -31,7 +31,7 @@ import ( ) // validateCollectionNameRe validates collection names. -var validateCollectionNameRe = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]{0,119}$") +var validateCollectionNameRe = regexp.MustCompile("^[a-zA-Z_-][a-zA-Z0-9_-]{0,119}$") // Collections returns a sorted list of FerretDB collection names. // diff --git a/internal/handlers/pg/pgdb/databases.go b/internal/handlers/pg/pgdb/databases.go index da8967529daf..30cdfb9fe3a3 100644 --- a/internal/handlers/pg/pgdb/databases.go +++ b/internal/handlers/pg/pgdb/databases.go @@ -28,6 +28,8 @@ import ( ) // validateDatabaseNameRe validates FerretDB database / PostgreSQL schema names. +// +// TODO: https://github.com/FerretDB/FerretDB/issues/1321 var validateDatabaseNameRe = regexp.MustCompile("^[a-z_][a-z0-9_]{0,62}$") // Databases returns a sorted list of FerretDB database / PostgreSQL schema. diff --git a/website/docs/diff.md b/website/docs/diff.md index e6fe2bd6275c..0c87d1bc70ba 100644 --- a/website/docs/diff.md +++ b/website/docs/diff.md @@ -11,7 +11,8 @@ sidebar_position: 6 3. Document keys must not contain `$` sign. 4. Database and collection names restrictions: * name cannot start with the reserved prefix `_ferretdb_`; - * name must not include non-latin letters, spaces, dots, dollars or dashes; + * database name must not include non-latin letters, spaces, dots, dollars or dashes; + * collection name must not include non-latin letters, spaces, dots or dollars; * name must not start with a number; * database name cannot contain capital letters; * database name length cannot be more than 63 characters;