Skip to content
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

fix datetime validation #426

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Database/Validator/Datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function isValid($value): bool
return false;
}

[$year] = explode('-', $value);

if ((int)$year > 9999) {
return false;
}

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5730,7 +5730,17 @@ public function testCreateDatetime(): void
$this->assertInstanceOf(StructureException::class, $e);
}

try {
static::getDatabase()->createDocument('datetime', new Document([
'date' => '+055769-02-14T17:56:18.000Z'
]));
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(StructureException::class, $e);
}

$invalidDates = [
'+055769-02-14T17:56:18.000Z1',
'1975-12-06 00:00:61',
'16/01/2024 12:00:00AM'
];
Expand Down
Loading