Update regex to detect external links with attachments

Fixes #4359
This commit is contained in:
Slade 2020-02-05 19:46:13 -07:00 committed by GitHub
parent 528dc633aa
commit 0360c57c79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -74,7 +74,7 @@ class AttachmentLinkProvider extends BaseLinkProvider implements ExternalLinkPro
*/ */
public function match() public function match()
{ {
if (preg_match('/^https?:\/\/.*\.([^\/]+)$/', $this->userInput, $matches)) { if (preg_match('/^https?:\/\/.*\/.*\.([^\/]+)$/', $this->userInput, $matches)) {
return $this->isValidExtension($matches[1]); return $this->isValidExtension($matches[1]);
} }

View File

@ -40,6 +40,9 @@ class AttachmentLinkProviderTest extends Base
$attachmentLinkProvider->setUserTextInput(' https://kanboard.org/folder/archive.tar '); $attachmentLinkProvider->setUserTextInput(' https://kanboard.org/folder/archive.tar ');
$this->assertTrue($attachmentLinkProvider->match()); $this->assertTrue($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('https://www.github.io/folder/archive.zip');
$this->assertTrue($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('http:// invalid url'); $attachmentLinkProvider->setUserTextInput('http:// invalid url');
$this->assertFalse($attachmentLinkProvider->match()); $this->assertFalse($attachmentLinkProvider->match());
@ -54,6 +57,12 @@ class AttachmentLinkProviderTest extends Base
$attachmentLinkProvider->setUserTextInput('https://kanboard.org/folder/document.do'); $attachmentLinkProvider->setUserTextInput('https://kanboard.org/folder/document.do');
$this->assertFalse($attachmentLinkProvider->match()); $this->assertFalse($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('https://www.github.io/folder/document.html');
$this->assertFalse($attachmentLinkProvider->match());
$attachmentLinkProvider->setUserTextInput('https://www.github.io');
$this->assertFalse($attachmentLinkProvider->match());
} }
public function testGetLink() public function testGetLink()