Skip to content

Commit

Permalink
fix: handle non-url types in mastodon replies with hashtags
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Aug 30, 2024
1 parent ee93c5d commit eaf6bad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Microformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public function returnArraySave($values)
public function includesPageUrl(array|string $urls)
{
$urls = $this->returnArraySave($urls);
$url_validation_regex = "/^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$/";

foreach ($urls as $url) {
if(preg_match($url_validation_regex, $url) !== 1) {
continue;
}

$trimmedUrl = trim(Url::stripQuery($url));
if ($trimmedUrl === $this->pageUrl) {
return true;
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/MicroformatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ public function testIncludesPageUrlWithParams()
$this->assertTrue($result);
}

/**
* @group microformats
* @testdox includesPageUrl - should handle mastodon tag
*/
public function testIncludesPageUrlWithTags()
{
$urls = ['tag:uuid', 'https://indie-connector.tld?param=value'];

$microformats = new Microformats('https://indie-connector.tld');
$result = $microformats->includesPageUrl($urls);

$this->assertTrue($result);
}

/**
* @group microformats
* @testdox includesBaseUrl - should find matching url
Expand Down

0 comments on commit eaf6bad

Please sign in to comment.