diff --git a/lib/Service/PageService.php b/lib/Service/PageService.php index 343f559c6..e39a6e54c 100644 --- a/lib/Service/PageService.php +++ b/lib/Service/PageService.php @@ -1028,8 +1028,8 @@ public function getPageLink(string $collectiveName, PageInfo $pageInfo, bool $wi } public function matchBacklinks(PageInfo $pageInfo, string $content): bool { - $prefix = '/(\[[^\]]+\]\(|\<)'; - $suffix = '[\)\>]/'; + $prefix = '/(\[[^]]+]\(|<)'; + $suffix = '(( \([^)]+\))?\)|>)/'; $protocol = 'https?:\/\/'; $trustedDomainArray = array_map(static fn (string $domain) => str_replace('\*', '\w*', preg_quote($domain, '/')), (array)$this->config->getSystemValue('trusted_domains', [])); diff --git a/tests/Unit/Service/PageServiceTest.php b/tests/Unit/Service/PageServiceTest.php index 76b238d6e..6b6b39d83 100644 --- a/tests/Unit/Service/PageServiceTest.php +++ b/tests/Unit/Service/PageServiceTest.php @@ -331,6 +331,9 @@ public function testMatchBacklinks(): void { self::assertFalse($this->service->matchBacklinks($pageInfo, 'content with [a link to wrong host](https://anothercloud.com' . $urlPath . ') in it.')); self::assertFalse($this->service->matchBacklinks($pageInfo, 'content with [a link to wrong host](anothercloud.com' . $urlPath . ') in it.')); + // Relative link with fileId in [text](link (preview)) syntax + self::assertTrue($this->service->matchBacklinks($pageInfo, 'content with [a link](https://nextcloud.local' . $urlPath . ' (preview)) in it.')); + OC::$WEBROOT = 'mycloud'; // Relative link with fileId with webroot in [text](link) syntax