mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 04:04:03 +00:00
Validate in-memory DBs outside of isInMemory
isInMemory should check if the name looks ilke an in-memory database name and return bool (it shouldn't throw validation errors). Also, make the validation methods non-static.
This commit is contained in:
parent
429e0985fd
commit
ea20eb13b6
2 changed files with 17 additions and 23 deletions
|
|
@ -23,7 +23,7 @@ trait ValidatesDatabaseParameters
|
|||
* Used as the default allowlist in validateParameter(), which validates non-password
|
||||
* parameters such as database names or usernames.
|
||||
*/
|
||||
protected static function allowedParameterCharacters(): string
|
||||
protected function allowedParameterCharacters(): string
|
||||
{
|
||||
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ trait ValidatesDatabaseParameters
|
|||
* characters that can break out of the quoted SQL strings (so e.g.
|
||||
* ', ", \, and ` aren't allowed).
|
||||
*/
|
||||
protected static function allowedPasswordCharacters(): string
|
||||
protected function allowedPasswordCharacters(): string
|
||||
{
|
||||
return ' !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~';
|
||||
}
|
||||
|
|
@ -46,15 +46,15 @@ trait ValidatesDatabaseParameters
|
|||
* only contain allowed characters before used in SQL statements
|
||||
* (or paths in the case of SQLiteDatabaseManager).
|
||||
*
|
||||
* By default, only the characters in static::allowedParameterCharacters() are allowed.
|
||||
* By default, only the characters in allowedParameterCharacters() are allowed.
|
||||
*
|
||||
* Null parameters are skipped.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected static function validateParameter(string|array|null $parameters, string|null $allowedCharacters = null): void
|
||||
protected function validateParameter(string|array|null $parameters, string|null $allowedCharacters = null): void
|
||||
{
|
||||
$allowedCharacters ??= static::allowedParameterCharacters();
|
||||
$allowedCharacters ??= $this->allowedParameterCharacters();
|
||||
|
||||
foreach ((array) $parameters as $parameter) {
|
||||
if (is_null($parameter)) {
|
||||
|
|
@ -78,7 +78,7 @@ trait ValidatesDatabaseParameters
|
|||
}
|
||||
|
||||
/**
|
||||
* Ensure password only contains allowed characters (static::allowedPasswordCharacters())
|
||||
* Ensure password only contains allowed characters (allowedPasswordCharacters())
|
||||
* before used in SQL statements.
|
||||
*
|
||||
* Used in permission controlled managers as a shorthand for calling validateParameter()
|
||||
|
|
@ -86,8 +86,8 @@ trait ValidatesDatabaseParameters
|
|||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected static function validatePassword(string|null $password): void
|
||||
protected function validatePassword(string|null $password): void
|
||||
{
|
||||
static::validateParameter($password, allowedCharacters: static::allowedPasswordCharacters());
|
||||
$this->validateParameter($password, allowedCharacters: $this->allowedPasswordCharacters());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue