From 896a32c158abf57d2259926d9e8ca8e809d2e62c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Dec 2017 10:55:39 +0100 Subject: [PATCH] fix(parser) Allow URI template to be `/` only. --- src/Parser.php | 4 ++-- test/integration/Parser.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 90785ee..3434a2a 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -489,12 +489,12 @@ public function getHeaderType(string $headerContent, &$matches = []): int } // Resource section. - if (0 !== preg_match('/^(?[^\[]+)\[(?\/[^\]]+)\]/', $headerContent, $matches)) { + if (0 !== preg_match('/^(?[^\[]+)\[(?\/[^\]]*)\]/', $headerContent, $matches)) { return self::HEADER_RESOURCE; } // Action section. - if (0 !== preg_match('/(?:^(?[A-Z]+)$)|(?:^(?[^\[]+)\[(?[A-Z]+)(?:\h+(?\/[^\]]+))?\])/', $headerContent, $matches)) { + if (0 !== preg_match('/(?:^(?[A-Z]+)$)|(?:^(?[^\[]+)\[(?[A-Z]+)(?:\h+(?\/[^\]]*))?\])/', $headerContent, $matches)) { if (empty($matches['requestMethod1'])) { $matches['requestMethod1'] = null; } diff --git a/test/integration/Parser.php b/test/integration/Parser.php index be8e7a7..74332ae 100644 --- a/test/integration/Parser.php +++ b/test/integration/Parser.php @@ -115,14 +115,14 @@ public function test_one_empty_resource() $this ->given( $parser = new SUT(), - $datum = '# Foo Bar [/foo/bar]' + $datum = '# Foo Bar [/]' ) ->when($result = $parser->parse($datum)) ->then ->let( $resource = new IR\Resource(), $resource->name = 'Foo Bar', - $resource->uriTemplate = '/foo/bar', + $resource->uriTemplate = '/', $document = new IR\Document(), $document->resources[] = $resource