-
Notifications
You must be signed in to change notification settings - Fork 55
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
Open
fogelito
wants to merge
20
commits into
main
Choose a base branch
from
upsert-text-truncation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e4390b2
validate texts
fogelito cbdc3cf
validate texts
fogelito 99440b9
validate texts
fogelito dde22fe
Structure test
fogelito 29b8677
change name
fogelito 79c7d27
all inline
fogelito 84e3950
Change inlines
fogelito 44852f1
line
fogelito 24cb977
32 bit systems
fogelito 1da4b3f
Merge branch 'main' of github.com:utopia-php/database into upsert-tex…
fogelito 3dc94f9
Update main
fogelito bcfad73
Check null values passes
fogelito b5a2164
Revert
fogelito cf959b1
Merge branch 'main' of github.com:utopia-php/database into upsert-tex…
fogelito 93ef31c
pull main
fogelito 05e58dd
messages
fogelito 5656ad4
fix SQLite.php
fogelito d81506e
line
fogelito 29d2d43
ByteLength
fogelito 8c7b131
tests
fogelito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
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; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.