Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check both card reference url patterns #5262

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Reference/CardReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public function matchReference(string $referenceText): bool {
$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, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;
$noIndexMatchFull = preg_match('/^' . preg_quote($start, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;
$indexMatchFull = preg_match('/^' . preg_quote($startIndex, '/') . '\/#\/board\/[0-9]+\/card\/[0-9]+$/', $referenceText) === 1;

// link example: https://nextcloud.local/index.php/apps/deck/card/11
$noIndexMatch = preg_match('/^' . preg_quote($start, '/') . '\/card\/[0-9]+$/', $referenceText) === 1;
$indexMatch = preg_match('/^' . preg_quote($startIndex, '/') . '\/card\/[0-9]+$/', $referenceText) === 1;

return $noIndexMatch || $indexMatch;
return $noIndexMatchFull || $indexMatchFull || $noIndexMatch || $indexMatch;
}

/**
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/Reference/CardReferenceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Reference;

use OCA\Deck\Reference\CardReferenceProvider;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CardService;
use OCA\Deck\Service\StackService;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;

class CardReferenceProviderTest extends TestCase {
public function setUp() : void {
parent::setUp();

$this->cardService = $this->createMock(CardService::class);
$this->boardService = $this->createMock(BoardService::class);
$this->stackService = $this->createMock(StackService::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10n = $this->createMock(IL10N::class);
$this->userId = null;

$this->provider = new CardReferenceProvider(
$this->cardService,
$this->boardService,
$this->stackService,
$this->urlGenerator,
$this->l10n,
$this->userId,
);
}

public function testUrl() {
$this->urlGenerator->expects($this->any())
->method('getAbsoluteURL')
->willReturnCallback(function ($path) {
return 'https://localhost/' . ltrim($path, '/');
});
self::assertFalse($this->provider->matchReference('https://nextcloud.com'));
self::assertTrue($this->provider->matchReference('https://localhost/apps/deck/#/board/2/card/11'));
self::assertTrue($this->provider->matchReference('https://localhost/index.php/apps/deck/#/board/2/card/11'));
self::assertTrue($this->provider->matchReference('https://localhost/apps/deck/card/11'));
self::assertTrue($this->provider->matchReference('https://localhost/index.php/apps/deck/card/11'));
}
}