From 98619dc3198181ad44736afdb82cf74ae31a296d Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 26 Apr 2023 10:08:22 +0200 Subject: [PATCH] Protect img tags from replacing mentions --- includes/class-mention.php | 6 ++++++ tests/test-class-activitypub-mention.php | 1 + 2 files changed, 7 insertions(+) diff --git a/includes/class-mention.php b/includes/class-mention.php index e0930cc..9c93d80 100644 --- a/includes/class-mention.php +++ b/includes/class-mention.php @@ -46,6 +46,12 @@ class Mention { $the_content ); + $the_content = preg_replace_callback( + '#]+>#i', + $protect, + $the_content + ); + $the_content = \preg_replace_callback( '/@' . ACTIVITYPUB_USERNAME_REGEXP . '/', array( self::class, 'replace_with_links' ), $the_content ); $the_content = str_replace( array_reverse( array_keys( $protected_tags ) ), array_reverse( array_values( $protected_tags ) ), $the_content ); diff --git a/tests/test-class-activitypub-mention.php b/tests/test-class-activitypub-mention.php index 6f6b9ff..ca7395f 100644 --- a/tests/test-class-activitypub-mention.php +++ b/tests/test-class-activitypub-mention.php @@ -31,6 +31,7 @@ ENDPRE; array( 'hallo @pfefferle@notiz.blog test', 'hallo @pfefferle@notiz.blog test' ), array( 'hallo @pfefferle@notiz.blog test', 'hallo @pfefferle@notiz.blog test' ), array( 'hallo @pfefferle@notiz.blog test', 'hallo @pfefferle@notiz.blog test' ), + array( 'hallo https://notiz.blog/@pfefferle/ test', 'hallo https://notiz.blog/@pfefferle/ test' ), array( $code, $code ), array( $pre, $pre ), );