From 24a45bc30de7b3743063d031befe428fa428e3cd Mon Sep 17 00:00:00 2001 From: David Kagan <102766847+DKagan07@users.noreply.github.com> Date: Fri, 7 Apr 2023 15:08:07 -0400 Subject: [PATCH] Cloud 1475 (#2371) * working on incorporating regex logic * Implemented a validation check for database name with given rules in doc within controller * fixing tests to pass * reflecting changes to match docs * fixed tests further, hopefully * for sure fixed integration tests, and moved validation check * integration tests passed, go test now will pass * fixed name size to 230 due to previous commit acknowledgement * fixed field test negative validations * added missing comma --- dax/controller/schemar/errors.go | 2 +- dax/controller/sqldb/schemar.go | 5 +++-- pilosa.go | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dax/controller/schemar/errors.go b/dax/controller/schemar/errors.go index 710ed9b4c..863a04e51 100644 --- a/dax/controller/schemar/errors.go +++ b/dax/controller/schemar/errors.go @@ -28,7 +28,7 @@ func NewErrDatabaseIDInvalid(databaseID dax.DatabaseID) error { func NewErrDatabaseNameInvalid(databaseName dax.DatabaseName) error { return errors.New( ErrCodeDatabaseNameInvalid, - fmt.Sprintf("database name '%s' is invalid", databaseName), + fmt.Sprintf("invalid database name %s", databaseName), ) } diff --git a/dax/controller/sqldb/schemar.go b/dax/controller/sqldb/schemar.go index 0191b8b75..f27f5994e 100644 --- a/dax/controller/sqldb/schemar.go +++ b/dax/controller/sqldb/schemar.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" + featurebase "github.com/featurebasedb/featurebase/v3" "github.com/featurebasedb/featurebase/v3/dax" "github.com/featurebasedb/featurebase/v3/dax/controller/schemar" "github.com/featurebasedb/featurebase/v3/dax/models" @@ -34,8 +35,8 @@ func (s *Schemar) CreateDatabase(tx dax.Transaction, qdb *dax.QualifiedDatabase) return schemar.NewErrDatabaseIDInvalid(qdb.ID) } - // Ensure the database name is not blank. - if qdb.Name == "" { + // Sanitizing database name + if err := featurebase.ValidateName(string(qdb.Name)); err != nil { return schemar.NewErrDatabaseNameInvalid(qdb.Name) } diff --git a/pilosa.go b/pilosa.go index a95417216..e416775fb 100644 --- a/pilosa.go +++ b/pilosa.go @@ -135,6 +135,10 @@ func newPreconditionFailedError(err error) PreconditionFailedError { } // Regular expression to validate index and field names. +// The lowest limitation I've seen on any filesystem we care about is 255 +// characters. 230 leaves enough space that an index or field could be +// backed up and have a timestamp and file extension appended while +// still allowing for much longer index and field names. --Jaffee var nameRegexp = regexp.MustCompile(`^[a-z][a-z0-9Θ_-]{0,229}$`) // TimeFormat is the go-style time format used to parse string dates.