Skip to content

Commit

Permalink
Merge pull request #14400 from jeabakker/fixes-5
Browse files Browse the repository at this point in the history
fix(views): correctly handle errors in mention parsing
  • Loading branch information
jeabakker committed Jun 28, 2023
2 parents e071a0e + 7285654 commit 8e948c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion engine/classes/Elgg/Views/HtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function parseMentions(string $text): string {
return $preceding_char . $replacement . $period;
};

return preg_replace_callback(self::MENTION_REGEX, $callback, $text);
return preg_replace_callback(self::MENTION_REGEX, $callback, $text) ?? $text;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions engine/classes/ElggUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,17 @@ public function getObjects(array $options = []) {
/**
* Get a user's owner GUID
*
* Returns it's own GUID if the user is not owned.
* Returns its own GUID if the user is not owned.
*
* @return int
*/
public function getOwnerGUID(): int {
if ($this->owner_guid == 0) {
return $this->guid;
$owner_guid = parent::getOwnerGUID();
if ($owner_guid === 0) {
$owner_guid = (int) $this->guid;
}

return $this->owner_guid;
return $owner_guid;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions mod/thewire/lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ function thewire_save_post(string $text, int $userid, int $access_id, int $paren
*/
function thewire_get_hashtags(string $text): array {
// beginning of text or white space followed by hashtag
// hashtag must begin with # and contain at least one character not digit, space, or punctuation
// the hashtag must begin with # and contain at least one character not digit, space, or punctuation
$matches = [];
preg_match_all('/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', $text, $matches);
preg_match_all('/(^|[^\w])#(\w+[^\s\d[:punct:]\x{2018}-\x{201F}]+\w*)/u', $text, $matches);

return $matches[2];
return $matches[2] ?? [];
}

/**
Expand All @@ -113,7 +113,7 @@ function thewire_filter(string $text): string {

// hashtags
$text = preg_replace_callback(
'/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/',
'/(^|[^\w])#(\w+[^\s\d[:punct:]\x{2018}-\x{201F}]+\w*)/u',
function ($matches) {
$tag = elgg_extract(2, $matches);
$url = elgg_generate_url('collection:object:thewire:tag', [
Expand All @@ -123,7 +123,7 @@ function ($matches) {

return elgg_extract(1, $matches) . $link;
},
$text);
$text) ?? $text;

return trim($text);
}

0 comments on commit 8e948c9

Please sign in to comment.