Skip to content

Commit

Permalink
Merge branch '6.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Aug 24, 2017
2 parents 420a68d + f276e4c commit 58b679f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
18 changes: 18 additions & 0 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Expand Up @@ -942,4 +942,22 @@ public function testLookUpThrowsNotFoundExceptionWithLanguageFilter()
$loadedAlias = $urlAliasService->lookUp('/Contact-Us', 'ger-DE');
/* END: Use Case */
}

/**
* Test for the lookUp() method.
*
* @see \eZ\Publish\API\Repository\URLAliasService::lookUp($url, $languageCode)
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function testLookUpThrowsInvalidArgumentException()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();

// Throws InvalidArgumentException
$loadedAlias = $urlAliasService->lookUp(str_repeat('/1', 99), 'ger-DE');
/* END: Use Case */
}
}
1 change: 1 addition & 0 deletions eZ/Publish/API/Repository/URLAliasService.php
Expand Up @@ -100,6 +100,7 @@ public function removeAliases(array $aliasList);
* @param string $languageCode
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the path does not exist or is not valid for the given language
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the path exceeded maximum depth level
*
* @return \eZ\Publish\API\Repository\Values\Content\URLAlias
*/
Expand Down
13 changes: 12 additions & 1 deletion eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php
Expand Up @@ -8,6 +8,7 @@
*/
namespace eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias;

use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
use eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler as UrlAliasHandlerInterface;
use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
Expand All @@ -34,6 +35,11 @@ class Handler implements UrlAliasHandlerInterface
*/
const CONTENT_REPOSITORY_ROOT_LOCATION_ID = 2;

/**
* The maximum level of alias depth.
*/
const MAX_URL_ALIAS_DEPTH_LEVEL = 60;

/**
* UrlAlias Gateway.
*
Expand Down Expand Up @@ -491,6 +497,7 @@ public function removeURLAliases(array $urlAliases)
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \RuntimeException
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
*
* @param string $url
*
Expand All @@ -503,12 +510,16 @@ public function lookup($url)
$urlHashes[$level] = $this->getHash($text);
}

$pathDepth = count($urlHashes);
if ($pathDepth > self::MAX_URL_ALIAS_DEPTH_LEVEL) {
throw new InvalidArgumentException('$urlHashes', 'Exceeded maximum depth level of content url alias.');
}

$data = $this->gateway->loadUrlAliasData($urlHashes);
if (empty($data)) {
throw new NotFoundException('URLAlias', $url);
}

$pathDepth = count($urlHashes);
$hierarchyData = array();
$isPathHistory = false;
for ($level = 0; $level < $pathDepth; ++$level) {
Expand Down
Expand Up @@ -70,6 +70,22 @@ public function testLookupThrowsNotFoundException()
$handler->lookup('wooden/iron');
}

/**
* Test for the lookup() method.
*
* Trying to lookup URL alias with exceeded path segments limit
*
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler::lookup
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @group location
* @group case-correction
*/
public function testLookupThrowsInvalidArgumentException()
{
$handler = $this->getHandler();
$handler->lookup(str_repeat('/1', 99));
}

public function providerForTestLookupLocationUrlAlias()
{
return array(
Expand Down
1 change: 1 addition & 0 deletions eZ/Publish/Core/Repository/URLAliasService.php
Expand Up @@ -608,6 +608,7 @@ protected function buildSPIUrlAlias(URLAlias $urlAlias)
* looks up the URLAlias for the given url.
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the path does not exist or is not valid for the given language
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the path exceeded maximum depth level
*
* @param string $url
* @param string $languageCode
Expand Down

0 comments on commit 58b679f

Please sign in to comment.