Skip to content

Commit 2380d22

Browse files
authored
fix(comments): stop hyperlinks truncating at hyphens (#30)
The auto-linkify regex for comment URLs used [\w/_\.]* for the path segment, which excludes '-'. A link like https://youtu.be/T1MnG-gKgF0 was rendered as a clickable https://youtu.be/T1MnG followed by plain-text -gKgF0. Added '-' to the path character class in all three places this regex is duplicated.
1 parent cfba83f commit 2380d22

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎web/pages/admin.bans.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ function bansBuildComments(array $commentres, $userbank, int $rowId, string $typ
13461346
$cdata['added'] = Config::time($crow['added']);
13471347
$commentText = html_entity_decode($crow['commenttxt'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
13481348
$commentText = encodePreservingBr($commentText);
1349-
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
1349+
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
13501350
$cdata['commenttxt'] = $commentText;
13511351

13521352
if (!empty($crow['edittime'])) {

‎web/pages/page.banlist.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ function setPostKey()
11231123
$commentText = html_entity_decode($crow['commenttxt'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
11241124
$commentText = encodePreservingBr($commentText);
11251125
// Parse links and wrap them in a <a href=""></a> tag to be easily clickable
1126-
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
1126+
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
11271127
$cdata['commenttxt'] = $commentText;
11281128

11291129
if (!empty($crow['edittime'])) {

‎web/pages/page.commslist.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ function setPostKey()
902902
$commentText = html_entity_decode($crow['commenttxt'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
903903
$commentText = encodePreservingBr($commentText);
904904
// Parse links and wrap them in a <a href=""></a> tag to be easily clickable
905-
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
905+
$commentText = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $commentText);
906906
$cdata['commenttxt'] = $commentText;
907907

908908
if (!empty($crow['edittime'])) {

0 commit comments

Comments
 (0)