diff --git a/composer.json b/composer.json index e8bfd50..163f51d 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "volt-test/php-sdk", "description": "Volt Test PHP SDK - A performance testing tool for PHP applications", "type": "library", - "version": "0.9.0", + "version": "0.9.1", "keywords": [ "volt-test", "php-sdk", diff --git a/src/Extractors/JsonExtractor.php b/src/Extractors/JsonExtractor.php index c7c6fb2..7a1cb17 100644 --- a/src/Extractors/JsonExtractor.php +++ b/src/Extractors/JsonExtractor.php @@ -44,10 +44,11 @@ public function validate(): bool if (empty($this->selector) || $this->selector === '$.') { throw new InvalidJsonPathException('JSON path cannot be empty'); } - // Validate the selector ex: $.meta.token + // Validate the selector ex: $.meta.token or $.data[0].name // Validate the selector follows proper JSON path format // Should start with $ followed by dot and valid path segments - if (! preg_match('/^\$(\.[a-zA-Z0-9_]+)*$/', $this->selector)) { + $pattern = '/^\$(\.[a-zA-Z0-9_]+|\[[0-9]+\])*$/'; + if (! preg_match($pattern, $this->selector)) { throw new InvalidJsonPathException('Invalid JSON path'); } diff --git a/src/Platform.php b/src/Platform.php index 5ca62a9..85f5de7 100644 --- a/src/Platform.php +++ b/src/Platform.php @@ -6,7 +6,7 @@ class Platform { private const BINARY_NAME = 'volt-test'; - private const ENGINE_CURRENT_VERSION = 'v0.1.1'; + private const ENGINE_CURRENT_VERSION = 'v0.9.1'; private const BASE_DOWNLOAD_URL = 'https://github.com/volt-test/binaries/releases/download'; private const SUPPORTED_PLATFORMS = [ 'linux-amd64' => 'volt-test-linux-amd64', diff --git a/tests/Units/JsonExtractorTest.php b/tests/Units/JsonExtractorTest.php index b16c437..6a7dcfb 100644 --- a/tests/Units/JsonExtractorTest.php +++ b/tests/Units/JsonExtractorTest.php @@ -46,6 +46,9 @@ public static function validJsonPathProvider(): array ['with_underscore'], ['with.numbers.123'], ['mixed.path_with.numbers123'], + ['mixed[0].path'], + ['mixed[0].path[1]'], + ['mixed[0].path[1].with[2].numbers[3]'], ]; } @@ -67,6 +70,12 @@ public static function invalidJsonPathProvider(): array ['$invalid.start'], ['invalid$.middle'], ['path.with.$'], + ['$.data[abc]'], + ['$.data[0].name[abc]'], + ['$.data[0].name[0].'], + ['$.data[0].name[0].[1]'], + ['$.data[0].name[0].[1].'], + ['$.data[0].name[0].[1].name'], ]; }