Skip to content

Commit

Permalink
Fixed NIL bug in isValid() method, reported by @ocubom in PR #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Apr 29, 2013
1 parent 79a655e commit 9d175d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Rhumsaa/Uuid/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ public static function isValid($uuid)
{
$uuid = str_replace(array('urn:', 'uuid:', '{', '}'), '', $uuid);

if ($uuid == self::NIL) {
return true;
}

if (!preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-5][0-9A-Fa-f]{3}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $uuid)) {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Rhumsaa/Uuid/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1334,4 +1334,13 @@ public function testIsValidTooLong()
$valid = Uuid::isValid('ff6f8cb0-c57da-51e1-9b21-0800200c9a66');
$this->assertFalse($valid);
}

/**
* @covers Rhumsaa\Uuid\Uuid::isValid
*/
public function testUsingNilAsValidUuid()
{
$this->assertInstanceOf('Rhumsaa\Uuid\Uuid', Uuid::uuid3(Uuid::NIL, 'randomtext'));
$this->assertInstanceOf('Rhumsaa\Uuid\Uuid', Uuid::uuid5(Uuid::NIL, 'randomtext'));
}
}

0 comments on commit 9d175d1

Please sign in to comment.