From 7a05177e0754f3202033cdaa823cbdfc02079e6a Mon Sep 17 00:00:00 2001 From: Cerys Date: Fri, 29 Nov 2024 11:17:25 +0000 Subject: [PATCH] relative path verification now in an outside accessible class --- src/QueryBuilder/QueryBuilderTrait.php | 3 ++- src/Utilities/RelativePath.php | 15 +++++++++++++++ tests/ValidateDeegraphPathTest.php | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Utilities/RelativePath.php create mode 100644 tests/ValidateDeegraphPathTest.php diff --git a/src/QueryBuilder/QueryBuilderTrait.php b/src/QueryBuilder/QueryBuilderTrait.php index 6993ce2..4fec8b1 100755 --- a/src/QueryBuilder/QueryBuilderTrait.php +++ b/src/QueryBuilder/QueryBuilderTrait.php @@ -12,6 +12,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQue use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder; +use Darksparrow\DeegraphInteractions\Utilities\RelativePath; use ReflectionClass; trait QueryBuilderTrait @@ -31,7 +32,7 @@ trait QueryBuilderTrait 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(); return $target; } diff --git a/src/Utilities/RelativePath.php b/src/Utilities/RelativePath.php new file mode 100644 index 0000000..900cc26 --- /dev/null +++ b/src/Utilities/RelativePath.php @@ -0,0 +1,15 @@ +