Skip to content

Commit

Permalink
fix(parser) Allow URI template to be / only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Dec 11, 2017
1 parent 2cbde0c commit 896a32c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ public function getHeaderType(string $headerContent, &$matches = []): int
}

// Resource section.
if (0 !== preg_match('/^(?<name>[^\[]+)\[(?<uriTemplate>\/[^\]]+)\]/', $headerContent, $matches)) {
if (0 !== preg_match('/^(?<name>[^\[]+)\[(?<uriTemplate>\/[^\]]*)\]/', $headerContent, $matches)) {
return self::HEADER_RESOURCE;
}

// Action section.
if (0 !== preg_match('/(?:^(?<requestMethod1>[A-Z]+)$)|(?:^(?<name>[^\[]+)\[(?<requestMethod2>[A-Z]+)(?:\h+(?<uriTemplate>\/[^\]]+))?\])/', $headerContent, $matches)) {
if (0 !== preg_match('/(?:^(?<requestMethod1>[A-Z]+)$)|(?:^(?<name>[^\[]+)\[(?<requestMethod2>[A-Z]+)(?:\h+(?<uriTemplate>\/[^\]]*))?\])/', $headerContent, $matches)) {
if (empty($matches['requestMethod1'])) {
$matches['requestMethod1'] = null;
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 896a32c

Please sign in to comment.