Skip to content

Commit

Permalink
Add support for parsing multi-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Oct 24, 2016
1 parent 604278c commit 5d6a7c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -349,7 +349,7 @@ protected function _parseExtension($url)
if (empty($this->_extensions)) {
return [$url, null];
}
preg_match('/\.([0-9a-z]*)$/', $url, $match);
preg_match('/\.([0-9a-z\.]*)$/', $url, $match);
if (empty($match[1])) {
return [$url, null];
}
Expand Down
12 changes: 11 additions & 1 deletion tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -109,7 +109,7 @@ public function testRouteParsingWithExtensions()
$result = $route->parse('/posts/index.pdf', 'GET');
$this->assertFalse(isset($result['_ext']));

$route->extensions(['pdf', 'json', 'xml']);
$route->extensions(['pdf', 'json', 'xml', 'xml.gz']);
$result = $route->parse('/posts/index.pdf', 'GET');
$this->assertEquals('pdf', $result['_ext']);

Expand All @@ -118,6 +118,9 @@ public function testRouteParsingWithExtensions()

$result = $route->parse('/posts/index.xml', 'GET');
$this->assertEquals('xml', $result['_ext']);

$result = $route->parse('/posts/index.xml.gz', 'GET');
$this->assertEquals('xml.gz', $result['_ext']);
}

/**
Expand Down Expand Up @@ -619,6 +622,13 @@ public function testMatchWithExtension()
'c' => 'd'
]);
$this->assertEquals('/posts/view/1.json?id=b&c=d', $result);

$result = $route->match([
'controller' => 'posts',
'action' => 'index',
'_ext' => 'json.gz',
]);
$this->assertEquals('/posts/index.json.gz', $result);
}

/**
Expand Down

0 comments on commit 5d6a7c4

Please sign in to comment.