From bf594a91bc44f56048e7ccbd9b6b9898654d1db5 Mon Sep 17 00:00:00 2001 From: RafaJEstabile Date: Fri, 23 Jan 2026 16:57:50 -0300 Subject: [PATCH 1/2] fixing validation --- src/Ulid.php | 12 ++++++++---- src/UlidConstants.php | 1 + tests/UlidTest.php | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Ulid.php b/src/Ulid.php index d0d4bef..722f008 100755 --- a/src/Ulid.php +++ b/src/Ulid.php @@ -16,14 +16,18 @@ class Ulid * @param string $ulid * @return bool */ - public function isValidFormat( - string $ulid - ): bool { + public function isValidFormat(string $ulid): bool + { $validator = UlidConstants::TIME_LENGTH + UlidConstants::RANDOM_LENGTH; + if (strlen($ulid) !== $validator) { return false; } - return true; + + return preg_match( + UlidConstants::REGEX, + $ulid + ) === 1; } /** diff --git a/src/UlidConstants.php b/src/UlidConstants.php index 992a9c2..58dcc11 100755 --- a/src/UlidConstants.php +++ b/src/UlidConstants.php @@ -9,4 +9,5 @@ class UlidConstants const TIME_MAX = 281474976710655; const TIME_LENGTH = 10; const RANDOM_LENGTH = 16; + const REGEX = '/^[0-9A-HJKMNP-TV-Z]{26}$/ '; } diff --git a/tests/UlidTest.php b/tests/UlidTest.php index 5689cdf..9e6ad7b 100755 --- a/tests/UlidTest.php +++ b/tests/UlidTest.php @@ -230,6 +230,19 @@ public function testDecodeTimeInvalidTime() $ulid->decodeTime('QS234SAD23RADSWRA3FADQ3RS2'); } + /** + * @covers Ulid\Ulid::isValidFormat + */ + public function testIsValidFormatDoesNotValidateCharacters() + { + $ulid = new Ulid(); + + $result = $ulid->isValidFormat('01E475VQGHNW990PVHXFDT4C6W'); + + $this->assertTrue($result); + } + + protected function tearDown(): void { // From 46c05f87765c8aaaf41678f3b56402defc835de9 Mon Sep 17 00:00:00 2001 From: LeoDiSarli Date: Mon, 26 Jan 2026 11:10:32 -0300 Subject: [PATCH 2/2] fixing docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 03d83cb..aa16942 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: ulid-php-lib: build: context: ./ - dockerfile: ./ops/Dockerfile + dockerfile: ./contrib/Dockerfile container_name: ulid-php-lib volumes: - ./:/var/www/html