diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php index 342320d..41ed483 100644 --- a/includes/class-hashtag.php +++ b/includes/class-hashtag.php @@ -20,7 +20,7 @@ class Hashtag { /** * Filter to save #tags as real WordPress tags * - * @param int $id the rev-id + * @param int $id the rev-id * @param WP_Post $post the post * * @return @@ -44,6 +44,16 @@ class Hashtag { */ public static function the_content( $the_content ) { $protected_tags = array(); + $the_content = preg_replace_callback( + '#<(code|textarea|style)\b[^>]*>.*?]*>#i', + function( $m ) use ( &$protected_tags ) { + $c = count( $protected_tags ); + $protect = '!#!#PROTECT' . $c . '#!#!'; + $protected_tags[ $protect ] = $m[0]; + return $protect; + }, + $the_content + ); $the_content = preg_replace_callback( '#<[^>]+>#i', function( $m ) use ( &$protected_tags ) { diff --git a/includes/class-mention.php b/includes/class-mention.php index 0227d8a..23c0c59 100644 --- a/includes/class-mention.php +++ b/includes/class-mention.php @@ -24,6 +24,16 @@ class Mention { */ public static function the_content( $the_content ) { $protected_tags = array(); + $the_content = preg_replace_callback( + '#<(code|textarea|style)\b[^>]*>.*?]*>#i', + function( $m ) use ( &$protected_tags ) { + $c = count( $protected_tags ); + $protect = '!#!#PROTECT' . $c . '#!#!'; + $protected_tags[ $protect ] = $m[0]; + return $protect; + }, + $the_content + ); $the_content = preg_replace_callback( '#]+>.*?#i', function( $m ) use ( &$protected_tags ) { @@ -68,7 +78,7 @@ class Mention { /** * Extract the mentions from the post_content. * - * @param array $mentions The already found mentions. + * @param array $mentions The already found mentions. * @param string $post_content The post content. * @return mixed The discovered mentions. */ diff --git a/tests/test-class-activitypub-hashtag.php b/tests/test-class-activitypub-hashtag.php index 5c207bd..0c7c6b0 100644 --- a/tests/test-class-activitypub-hashtag.php +++ b/tests/test-class-activitypub-hashtag.php @@ -5,6 +5,7 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase { */ public function test_the_content( $content, $content_with_hashtag ) { \wp_create_term( 'object', 'post_tag' ); + \wp_create_term( 'ccc', 'post_tag' ); $object = \get_term_by( 'name', 'object', 'post_tag' ); $link = \get_term_link( $object, 'post_tag' ); @@ -14,6 +15,15 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase { } public function the_content_provider() { + $code = 'text with some #object and tag inside'; + $style = << + + +ENDSTYLE; + $textarea = ''; return array( array( 'test', 'test' ), array( '#test', '#test' ), @@ -27,6 +37,9 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase { array( '
#object
', '
#object
' ), array( '
#object', '#object' ), array( '
object', '
object' ), + array( $code, $code ), + array( $style, $style ), + array( $textarea, $textarea ), ); } } diff --git a/tests/test-class-activitypub-mention.php b/tests/test-class-activitypub-mention.php index e777dff..e4054d0 100644 --- a/tests/test-class-activitypub-mention.php +++ b/tests/test-class-activitypub-mention.php @@ -2,8 +2,8 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP { public static $users = array( 'username@example.org' => array( - 'url' => 'https://example.org/users/username', - 'name' => 'username', + 'url' => 'https://example.org/users/username', + 'name' => 'username', ), ); /** @@ -18,12 +18,14 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP { } public function the_content_provider() { + $code = 'hallo @username@example.org test'; return array( array( 'hallo @username@example.org test', 'hallo @username test' ), array( 'hallo @pfefferle@notiz.blog test', 'hallo @pfefferle 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 @pfefferle@notiz.blog test', 'hallo @pfefferle@notiz.blog test' ), + array( $code, $code ), ); }