Browse Source

relative path verification now in an outside accessible class

dev
Cerys 4 weeks ago
parent
commit
7a05177e07
  1. 3
      src/QueryBuilder/QueryBuilderTrait.php
  2. 15
      src/Utilities/RelativePath.php
  3. 20
      tests/ValidateDeegraphPathTest.php

3
src/QueryBuilder/QueryBuilderTrait.php

@ -12,6 +12,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder;
use Darksparrow\DeegraphInteractions\Utilities\RelativePath;
use ReflectionClass; use ReflectionClass;
trait QueryBuilderTrait trait QueryBuilderTrait
@ -31,7 +32,7 @@ trait QueryBuilderTrait
protected function ValidateDeegraphPath(string $target): string protected function ValidateDeegraphPath(string $target): string
{ {
if (!preg_match(pattern: "/(^(\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\})$)|(^\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\}(\/([a-z][a-z0-9]*|[0-9]+|#|\*))+$)|(^(([a-z][a-z0-9]*|[0-9]+|#|\*))(\/([a-z][a-z0-9]*|[0-9]+|#|\*))*$)/", subject: $target)) if (!RelativePath::Validate($target))
throw new QueryBuilderInvalidInputException(); throw new QueryBuilderInvalidInputException();
return $target; return $target;
} }

15
src/Utilities/RelativePath.php

@ -0,0 +1,15 @@
<?php
namespace Darksparrow\DeegraphInteractions\Utilities;
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException;
class RelativePath
{
public static function Validate(string $target): bool
{
if (!preg_match(pattern: "/(^(\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\})$)|(^\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\}(\/([a-z][a-z0-9]*|[0-9]+|#|\*))+$)|(^(([a-z][a-z0-9]*|[0-9]+|#|\*))(\/([a-z][a-z0-9]*|[0-9]+|#|\*))*$)/", subject: $target))
return false;
return true;
}
}

20
tests/ValidateDeegraphPathTest.php

@ -0,0 +1,20 @@
<?php
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
use Darksparrow\DeegraphInteractions\Utilities\RelativePath;
use PHPUnit\Framework\TestCase;
final class ValidateDeegraphPathTest extends TestCase
{
public function testValidUUID()
{
self::assertTrue(RelativePath::Validate("{00000000-0000-0000-0000-000000000000}"));
}
public function testFullStop()
{
self::assertTrue(RelativePath::Validate("."));
}
}
Loading…
Cancel
Save