From 6cfcdb58cb5bcd222d04d23287bfacd60fc76638 Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Fri, 5 Jul 2024 09:23:07 -0400 Subject: [PATCH] Additional fix for CFM-312 --- .../SqlConnector/src/Model/Table/SqlProvisionersTable.php | 5 +++-- app/src/Lib/Traits/ValidationTrait.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/availableplugins/SqlConnector/src/Model/Table/SqlProvisionersTable.php b/app/availableplugins/SqlConnector/src/Model/Table/SqlProvisionersTable.php index b1b0db3c4..ba0835387 100644 --- a/app/availableplugins/SqlConnector/src/Model/Table/SqlProvisionersTable.php +++ b/app/availableplugins/SqlConnector/src/Model/Table/SqlProvisionersTable.php @@ -786,12 +786,13 @@ public function validationDefault(Validator $validator): Validator { $this->registerStringValidation($validator, $schema, 'table_prefix', true); - // Table prefixes must be alphanumeric and end in an underscore. + // Table prefixes must be alphanumeric and end in an underscore. We also allow + // dots for schema.table notation. // (We don't use validateSqlIdentifier because of the trailing underscore requirement.) $validator->add('table_prefix', [ 'format' => [ 'rule' => function ($value, $context) { - return (preg_match('/[\w]+_/', $value) ? true : __d('sql_connector', 'error.table_prefix')); + return (preg_match('/^[\w\.]+_$/', $value) ? true : __d('sql_connector', 'error.table_prefix')); } ] ]); diff --git a/app/src/Lib/Traits/ValidationTrait.php b/app/src/Lib/Traits/ValidationTrait.php index 2f987761b..6c62548b2 100644 --- a/app/src/Lib/Traits/ValidationTrait.php +++ b/app/src/Lib/Traits/ValidationTrait.php @@ -300,9 +300,10 @@ public function validateSqlIdentifier($value, array $context) { // Valid (portable) SQL identifiers begin with a letter or underscore, and // subsequent characters can also include digits. We'll be a little stricter // than we need to be for now by only accepting A-Z, when in fact certain - // additional characters (like á) are also acceptable. + // additional characters (like á) are also acceptable. We also accept dots + // to allow for schema.table notation. - if(!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $value)) { + if(!preg_match('/^[a-zA-Z_][a-zA-Z0-9_\.]*$/', $value)) { return __d('error', 'input.invalid'); }