fix(ReferenceProvider): Fix usage of preg_match 🙈

fixes #1993

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2023-03-21 14:06:53 +01:00
parent 913dee741f
commit 669704677e
1 changed files with 4 additions and 3 deletions

View File

@ -70,20 +70,21 @@ class BookmarkReferenceProvider extends ADiscoverableReferenceProvider {
* @inheritDoc
*/
public function matchReference(string $referenceText): bool {
\OC::$server->get(LoggerInterface::class)->warning('MATCH REFERENCE');
$start = $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID);
$startIndex = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID);
// link example: https://nextcloud.local/index.php/apps/deck/#/board/2/card/11
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/bookmarks\/[0-9]+$/', $referenceText) !== false;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/bookmarks\/[0-9]+$/', $referenceText) !== false;
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/bookmarks\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/bookmarks\/[0-9]+$/', $referenceText) === 1;
if ($noIndexMatch || $indexMatch) {
\OC::$server->get(LoggerInterface::class)->warning('MATCH BOOKMARK BY INTERNAL URL!');
return true;
}
try {
$this->bookmarkService->findByUrl($this->userId, $referenceText);
\OC::$server->get(LoggerInterface::class)->warning('MATCH BOOKMARK BY URL!');
return true;
} catch (UrlParseError|DoesNotExistException $e) {
return false;