Skip to content

Commit

Permalink
fix(backlinks): Detect links with title in markdown syntax
Browse files Browse the repository at this point in the history
This fixes detecting preview links, as they have `preview` set as title
in the markdown link syntax.

Fixes: #1451

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Sep 4, 2024
1 parent df90a98 commit b8275c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', []));
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Service/PageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8275c8

Please sign in to comment.