Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 58
Text attributes data truncation#893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e4390b2cbdc3cf99440b9dde22fe29b867779c7d2784e395044852f124cb9771da4b3f3dc94f9bcfad73b5a2164cf959b193ef31c05e58dd5656ad4d81506e29d2d438c7b13122a0dc34f641d5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -35,15 +35,6 @@ | ||
| */ | ||
| class SQLite extends MariaDB | ||
| { | ||
| /** | ||
| * MariaDB byte ceilings for TEXT-family types, mirrored so PRAGMA-based | ||
| * introspection produces the same characterMaximumLength values that | ||
| * INFORMATION_SCHEMA.COLUMNS would on MariaDB. | ||
| */ | ||
| private const MARIADB_TEXT_BYTES = '65535'; | ||
| private const MARIADB_MEDIUMTEXT_BYTES = '16777215'; | ||
| private const MARIADB_LONGTEXT_BYTES = '4294967295'; | ||
| /** Suffix appended to every FTS5 virtual table name created by this adapter. */ | ||
| private const FTS_TABLE_SUFFIX = '_fts'; | ||
| @@ -2973,19 +2964,25 @@ private function parseSqliteColumnType(string $declaration): array | ||
| break; | ||
| } | ||
| /** | ||
| * MariaDB byte ceilings for TEXT-family types, mirrored so PRAGMA-based | ||
| * introspection produces the same characterMaximumLength values that | ||
| * INFORMATION_SCHEMA.COLUMNS would on MariaDB. | ||
| */ | ||
| if ($this->emulateMySQL) { | ||
| switch ($dataType) { | ||
| case 'text': | ||
| $result['characterMaximumLength'] = self::MARIADB_TEXT_BYTES; | ||
| $result['characterMaximumLength'] = '' . Database::MAX_TEXT_BYTES; | ||
| break; | ||
| case 'mediumtext': | ||
| $result['characterMaximumLength'] = self::MARIADB_MEDIUMTEXT_BYTES; | ||
| $result['characterMaximumLength'] = '' . Database::MAX_MEDIUMTEXT_BYTES; | ||
| break; | ||
| case 'longtext': | ||
| case 'json': | ||
| $result['characterMaximumLength'] = self::MARIADB_LONGTEXT_BYTES; | ||
| $result['characterMaximumLength'] = '' . Database::MAX_LONGTEXT_BYTES; | ||
fogelito marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| break; | ||
| case 'tinyint': | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
| namespace Utopia\Database\Validator; | ||
| use Utopia\Validator; | ||
| /** | ||
| * ByteLength | ||
| * | ||
| * Validate that a string's byte length does not exceed a maximum. Unlike the | ||
| * character-based Text validator, this measures the actual stored size, which | ||
| * is what byte-capacity columns (e.g. MySQL/MariaDB TEXT family) are limited by. | ||
| */ | ||
| class ByteLength extends Validator | ||
| { | ||
| protected int $max; | ||
| /** | ||
| * @param int $max Maximum allowed byte length. Use 0 for unlimited. | ||
| */ | ||
| public function __construct(int $max) | ||
| { | ||
| $this->max = $max; | ||
| } | ||
| public function getDescription(): string | ||
| { | ||
| return 'Value must be a valid string no longer than ' . $this->max . ' bytes'; | ||
| } | ||
| public function isArray(): bool | ||
| { | ||
| return false; | ||
| } | ||
| public function getType(): string | ||
| { | ||
| return self::TYPE_STRING; | ||
| } | ||
| public function isValid(mixed $value): bool | ||
| { | ||
| if (!\is_string($value)) { | ||
| return false; | ||
| } | ||
| if ($this->max !== 0 && \strlen($value) > $this->max) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -353,10 +353,22 @@ protected function checkForInvalidAttributeValues(Document $document, array $str | ||
| $validators[] = new Sequence($this->idAttributeType, $attribute['$id'] === '$sequence'); | ||
| break; | ||
| case Database::VAR_VARCHAR: | ||
| case Database::VAR_TEXT: | ||
| $validators[] = new ByteLength($size); | ||
| $validators[] = new ByteLength(Database::MAX_TEXT_BYTES); | ||
| break; | ||
| case Database::VAR_MEDIUMTEXT: | ||
| $validators[] = new ByteLength($size); | ||
| $validators[] = new ByteLength(Database::MAX_MEDIUMTEXT_BYTES); | ||
| break; | ||
| case Database::VAR_LONGTEXT: | ||
| $validators[] = new ByteLength($size); | ||
| $validators[] = new ByteLength(Database::MAX_LONGTEXT_BYTES); | ||
| break; | ||
fogelito marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both? | ||
| case Database::VAR_VARCHAR: | ||
| case Database::VAR_STRING: | ||
| $validators[] = new Text($size, min: 0); | ||
| break; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.