Skip to content

Commit 2cf3fef

Browse files
committed
make candidates filter out invalid paths
1 parent 6f82c4c commit 2cf3fef

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Admin/RouteAdmin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ protected function configureFieldsForDefaults($dynamicDefaults)
163163
}
164164
}
165165

166+
if ($route && $route->getOption('add_format_pattern')) {
167+
$defaults['_format'] = array('_format', 'text', array('required' => true));
168+
}
169+
if ($route && $route->getOption('add_locale_pattern')) {
170+
$defaults['_locale'] = array('_format', 'text', array('required' => false));
171+
}
172+
166173
return $defaults;
167174
}
168175

Doctrine/Phpcr/PrefixCandidates.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;
1313

14+
use PHPCR\Util\PathHelper;
1415
use Doctrine\Common\Persistence\ManagerRegistry;
1516
use Doctrine\ODM\PHPCR\DocumentManager;
1617
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
@@ -68,7 +69,9 @@ public function isCandidate($name)
6869
{
6970
foreach ($this->getPrefixes() as $prefix) {
7071
// $name is the route document path
71-
if ($name === $prefix || 0 === strpos($name, $prefix . '/')) {
72+
if (($name === $prefix || 0 === strpos($name, $prefix . '/'))
73+
&& PathHelper::assertValidAbsolutePath($name, false, false)
74+
) {
7275
return true;
7376
}
7477
}
@@ -113,6 +116,13 @@ public function getCandidates(Request $request)
113116
}
114117
}
115118

119+
// filter out things like double // or trailing / - this would trigger an exception on the document manager.
120+
foreach ($candidates as $key => $candidate) {
121+
if (! PathHelper::assertValidAbsolutePath($candidate, false, false)) {
122+
unset($candidates[$key]);
123+
}
124+
}
125+
116126
return $candidates;
117127
}
118128

Tests/Functional/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ public function testGetRouteCollectionForRequestFormat()
9999
$this->assertEquals(null, $root->getDefault('_format'));
100100
}
101101

102+
/**
103+
* The root route will always be found.
104+
*/
102105
public function testGetRouteCollectionForRequestNophpcrUrl()
103106
{
104107
$collection = $this->repository->getRouteCollectionForRequest(Request::create(':///'));
105108
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
106-
$this->assertCount(0, $collection);
109+
$this->assertCount(1, $collection);
110+
$routes = $collection->all();
111+
list ($key, $route) = each($routes);
112+
$this->assertEquals(self::ROUTE_ROOT, $key);
107113
}
108114

109115
public function testGetRoutesByNames()
@@ -113,6 +119,7 @@ public function testGetRoutesByNames()
113119
$routeNames = array(
114120
self::ROUTE_ROOT . '/testroute/noroute/child',
115121
self::ROUTE_ROOT . '/testroute/noroute',
122+
self::ROUTE_ROOT . '/testroute/', // trailing slash is invalid for phpcr
116123
self::ROUTE_ROOT . '/testroute'
117124
);
118125

0 commit comments

Comments
 (0)