Commit 32c3e6b6 authored by Tino Goratsch's avatar Tino Goratsch

made it possible to rewrite inline URIs

parent c8b8bd56
......@@ -62,7 +62,7 @@ class RewriteInternalUri
{
$rootDir = str_replace('/', '\/', $this->appPath->getWebRoot());
$host = $this->request->getServer()->get('HTTP_HOST');
$pattern = '/<a([^>]+)href="(http(s?):\/\/' . $host . ')?(' . $rootDir . ')?(index\.php)?(\/?)((?i:[a-z\d_\-]+\/){2,})"/i';
$pattern = '/(<a([^>]+)href=")?(http(s?):\/\/' . $host . ')?(' . $rootDir . ')?(index\.php)?(\/?)((?i:[a-z\d_\-]+\/){2,})(")?/i';
return preg_replace_callback(
$pattern,
......@@ -78,11 +78,15 @@ class RewriteInternalUri
*/
private function rewriteInternalUriCallback(array $matches)
{
if ($this->internalUriValidationRule->isValid($matches[7]) === true) {
$resourceParts = explode('/', $matches[7]);
if ($this->internalUriValidationRule->isValid($matches[8]) === true) {
$resourceParts = explode('/', $matches[8]);
$path = $this->getResourcePath($resourceParts);
if ($this->controllerActionExists->controllerActionExists($path) === true) {
return '<a' . $matches[1] . 'href="' . $this->router->route($matches[7]) . '"';
if (!empty($matches[1])) {
return '<a' . $matches[2] . 'href="' . $this->router->route($matches[8]) . '"';
}
return $this->router->route($matches[8]);
}
}
......
......@@ -184,4 +184,39 @@ HTML;
->with($route)
->willReturn($alias);
}
public function testRewriteInternalUriWithMatchingInlineUri()
{
$this->setUpAppPathExpectations();
$this->setUpRequestMockExpectations();
$this->setUpValidationRuleMockExpectations(1, 'foo/bar/baz/', true);
$this->setUpControllerActionExistsMockExpectations(1, 'frontend/foo/bar/baz', false);
$this->setUpRouterMockExpectations(0, '', '');
$content = <<<HTML
http://example.com/foo/bar/baz/
HTML;
$this->assertEquals($content, $this->rewriteInternalUri->rewriteInternalUri($content));
}
public function testRewriteInternalUriWithMatchingInlineUriAndExistingAlias()
{
$this->setUpAppPathExpectations();
$this->setUpRequestMockExpectations();
$this->setUpValidationRuleMockExpectations(1, 'foo/bar/baz/', true);
$this->setUpControllerActionExistsMockExpectations(1, 'frontend/foo/bar/baz', true);
$this->setUpRouterMockExpectations(1, 'foo/bar/baz/', '/foo-bar/');
$content = <<<HTML
http://example.com/foo/bar/baz/
HTML;
$expected = <<<HTML
/foo-bar/
HTML;
$this->assertEquals($expected, $this->rewriteInternalUri->rewriteInternalUri($content));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment