Skip to content

Commit 9be8e29

Browse files
committed
Passthru max UID
1 parent 6ecd607 commit 9be8e29

5 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/Database/Database.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,6 +5151,7 @@ public function updateDocuments(
51515151
$indexes,
51525152
$this->adapter->getIdAttributeType(),
51535153
$this->maxQueryValues,
5154+
$this->adapter->getMaxUIDLength(),
51545155
$this->adapter->getMinDateTime(),
51555156
$this->adapter->getMaxDateTime(),
51565157
$this->adapter->getSupportForAttributes()
@@ -6710,6 +6711,7 @@ public function deleteDocuments(
67106711
$indexes,
67116712
$this->adapter->getIdAttributeType(),
67126713
$this->maxQueryValues,
6714+
$this->adapter->getMaxUIDLength(),
67136715
$this->adapter->getMinDateTime(),
67146716
$this->adapter->getMaxDateTime(),
67156717
$this->adapter->getSupportForAttributes()
@@ -6908,6 +6910,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
69086910
$indexes,
69096911
$this->adapter->getIdAttributeType(),
69106912
$this->maxQueryValues,
6913+
$this->adapter->getMaxUIDLength(),
69116914
$this->adapter->getMinDateTime(),
69126915
$this->adapter->getMaxDateTime(),
69136916
$this->adapter->getSupportForAttributes()
@@ -7139,6 +7142,7 @@ public function count(string $collection, array $queries = [], ?int $max = null)
71397142
$indexes,
71407143
$this->adapter->getIdAttributeType(),
71417144
$this->maxQueryValues,
7145+
$this->adapter->getMaxUIDLength(),
71427146
$this->adapter->getMinDateTime(),
71437147
$this->adapter->getMaxDateTime(),
71447148
$this->adapter->getSupportForAttributes()
@@ -7204,6 +7208,7 @@ public function sum(string $collection, string $attribute, array $queries = [],
72047208
$indexes,
72057209
$this->adapter->getIdAttributeType(),
72067210
$this->maxQueryValues,
7211+
$this->adapter->getMaxUIDLength(),
72077212
$this->adapter->getMinDateTime(),
72087213
$this->adapter->getMaxDateTime(),
72097214
$this->adapter->getSupportForAttributes()

src/Database/Validator/Key.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66

77
class Key extends Validator
88
{
9-
protected bool $allowInternal = false; // If true, you keys starting with $ are allowed
10-
11-
/**
12-
* Maximum length for Key validation
13-
*/
14-
protected int $maxLength;
15-
16-
/**
17-
* @var string
18-
*/
199
protected string $message;
2010

2111
/**
@@ -33,10 +23,10 @@ public function getDescription(): string
3323
/**
3424
* Expression constructor
3525
*/
36-
public function __construct(bool $allowInternal = false, int $maxLength = 255)
37-
{
38-
$this->allowInternal = $allowInternal;
39-
$this->maxLength = $maxLength;
26+
public function __construct(
27+
private readonly bool $allowInternal = false,
28+
private readonly int $maxLength = 36,
29+
) {
4030
$this->message = 'Parameter must contain at most ' . $this->maxLength . ' chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char';
4131
}
4232

@@ -46,7 +36,6 @@ public function __construct(bool $allowInternal = false, int $maxLength = 255)
4636
* Returns true if valid or false if not.
4737
*
4838
* @param $value
49-
*
5039
* @return bool
5140
*/
5241
public function isValid($value): bool
@@ -59,15 +48,14 @@ public function isValid($value): bool
5948
return false;
6049
}
6150

62-
// no leading special characters
51+
// No leading special characters
6352
$leading = \mb_substr($value, 0, 1);
6453
if ($leading === '_' || $leading === '.' || $leading === '-') {
6554
return false;
6655
}
6756

6857
$isInternal = $leading === '$';
6958

70-
7159
if ($isInternal && !$this->allowInternal) {
7260
return false;
7361
}
@@ -83,6 +71,7 @@ public function isValid($value): bool
8371
if (\preg_match('/[^A-Za-z0-9\_\-\.]/', $value)) {
8472
return false;
8573
}
74+
8675
// At most maxLength chars
8776
if (\mb_strlen($value) > $this->maxLength) {
8877
return false;

src/Database/Validator/Queries/Documents.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Utopia\Database\Validator\Queries;
44

5-
use Exception;
65
use Utopia\Database\Database;
76
use Utopia\Database\Document;
87
use Utopia\Database\Validator\IndexedQueries;
@@ -16,18 +15,21 @@
1615
class Documents extends IndexedQueries
1716
{
1817
/**
19-
* Expression constructor
20-
*
2118
* @param array<mixed> $attributes
2219
* @param array<mixed> $indexes
2320
* @param string $idAttributeType
24-
* @throws Exception
21+
* @param int $maxValuesCount
22+
* @param \DateTime $minAllowedDate
23+
* @param \DateTime $maxAllowedDate
24+
* @param bool $supportForAttributes
25+
* @throws \Utopia\Database\Exception
2526
*/
2627
public function __construct(
2728
array $attributes,
2829
array $indexes,
2930
string $idAttributeType,
3031
int $maxValuesCount = 5000,
32+
int $maxUIDLength = 36,
3133
\DateTime $minAllowedDate = new \DateTime('0000-01-01'),
3234
\DateTime $maxAllowedDate = new \DateTime('9999-12-31'),
3335
bool $supportForAttributes = true
@@ -60,7 +62,7 @@ public function __construct(
6062
$validators = [
6163
new Limit(),
6264
new Offset(),
63-
new Cursor(),
65+
new Cursor($maxUIDLength),
6466
new Filter(
6567
$attributes,
6668
$idAttributeType,

src/Database/Validator/Query/Cursor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
class Cursor extends Base
1010
{
11+
public function __construct(private readonly int $maxLength = 36)
12+
{
13+
}
14+
1115
/**
1216
* Is valid.
1317
*
@@ -33,7 +37,7 @@ public function isValid($value): bool
3337
$cursor = $cursor->getId();
3438
}
3539

36-
$validator = new UID();
40+
$validator = new UID($this->maxLength);
3741
if ($validator->isValid($cursor)) {
3842
return true;
3943
}

src/Database/Validator/UID.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class UID extends Key
77
/**
88
* Expression constructor
99
*/
10-
public function __construct(int $maxLength = 255)
10+
public function __construct(int $maxLength = 36)
1111
{
1212
parent::__construct(false, $maxLength);
1313
}

0 commit comments

Comments
 (0)