Skip to content

Commit

Permalink
Additional fix for CFM-312
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jul 5, 2024
1 parent fa20d7b commit 6cfcdb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
]
]);
Expand Down
5 changes: 3 additions & 2 deletions app/src/Lib/Traits/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit 6cfcdb5

Please sign in to comment.