Skip to content

Commit c6c5c8b

Browse files
UFTimmydbu
authored andcommitted
Fix for invalid Jackrabbit characters in URLs (#436)
* Remove routes with invalid PHPCR characters * Disallow URLs with spaces adjacent to slashes
1 parent 38829bf commit c6c5c8b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Doctrine/Phpcr/PrefixCandidates.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getCandidates(Request $request)
118118

119119
// filter out things like double // or trailing / - this would trigger an exception on the document manager.
120120
foreach ($candidates as $key => $candidate) {
121-
if (!PathHelper::assertValidAbsolutePath($candidate, false, false)) {
121+
if (!$this->isCandidateValid($candidate)) {
122122
unset($candidates[$key]);
123123
}
124124
}
@@ -166,6 +166,30 @@ public function setManagerName($manager)
166166
$this->managerName = $manager;
167167
}
168168

169+
/**
170+
* @param string $candidate The candidate path to check
171+
*
172+
* @return bool
173+
*/
174+
protected function isCandidateValid($candidate)
175+
{
176+
// Candidates cannot start or end with a space in Jackrabbit.
177+
if (' ' === \substr($candidate, 0, 1) || ' ' === \substr($candidate, -1)) {
178+
return false;
179+
}
180+
181+
// Jackrabbit does not allow spaces before or after the path separator.
182+
if (false !== \strpos($candidate, ' /') || false !== \strpos($candidate, '/ ')) {
183+
return false;
184+
}
185+
186+
if (!PathHelper::assertValidAbsolutePath($candidate, false, false)) {
187+
return false;
188+
}
189+
190+
return true;
191+
}
192+
169193
/**
170194
* {@inheritdoc}
171195
*

src/Doctrine/Phpcr/RouteProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ public function __construct(
6464
*/
6565
public function getCandidates(Request $request)
6666
{
67-
if (false !== strpos($request->getPathInfo(), ':')) {
68-
return [];
67+
$invalidCharacters = [':', '[', ']'];
68+
foreach ($invalidCharacters as $invalidCharacter) {
69+
if (false !== strpos($request->getPathInfo(), $invalidCharacter)) {
70+
return [];
71+
}
6972
}
7073

7174
return $this->candidatesStrategy->getCandidates($request);

0 commit comments

Comments
 (0)