From e7894f4c4addf4a9b20d76ca9158f0ec3ac78e62 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 27 Jan 2023 16:55:52 +0100 Subject: [PATCH] Also protect

---
 includes/class-hashtag.php               | 2 +-
 includes/class-mention.php               | 2 +-
 tests/test-class-activitypub-hashtag.php | 8 ++++++++
 tests/test-class-activitypub-mention.php | 7 +++++++
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/includes/class-hashtag.php b/includes/class-hashtag.php
index 41ed483..cbdb7df 100644
--- a/includes/class-hashtag.php
+++ b/includes/class-hashtag.php
@@ -45,7 +45,7 @@ class Hashtag {
 	public static function the_content( $the_content ) {
 		$protected_tags = array();
 		$the_content = preg_replace_callback(
-			'#<(code|textarea|style)\b[^>]*>.*?]*>#i',
+			'#<(pre|code|textarea|style)\b[^>]*>.*?]*>#is',
 			function( $m ) use ( &$protected_tags ) {
 				$c = count( $protected_tags );
 				$protect = '!#!#PROTECT' . $c . '#!#!';
diff --git a/includes/class-mention.php b/includes/class-mention.php
index 23c0c59..1912dfa 100644
--- a/includes/class-mention.php
+++ b/includes/class-mention.php
@@ -25,7 +25,7 @@ class Mention {
 	public static function the_content( $the_content ) {
 		$protected_tags = array();
 		$the_content = preg_replace_callback(
-			'#<(code|textarea|style)\b[^>]*>.*?]*>#i',
+			'#<(pre|code|textarea|style)\b[^>]*>.*?]*>#is',
 			function( $m ) use ( &$protected_tags ) {
 				$c = count( $protected_tags );
 				$protect = '!#!#PROTECT' . $c . '#!#!';
diff --git a/tests/test-class-activitypub-hashtag.php b/tests/test-class-activitypub-hashtag.php
index 0c7c6b0..319b47d 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( 'touch', 'post_tag' );
 		\wp_create_term( 'ccc', 'post_tag' );
 		$object = \get_term_by( 'name', 'object', 'post_tag' );
 		$link = \get_term_link( $object, 'post_tag' );
@@ -23,6 +24,12 @@ color: #ccc;
 ]]>
 
 ENDSTYLE;
+		$pre = <<
+Please don't #touch
+  this.
+
+ENDPRE; $textarea = ''; return array( array( 'test', 'test' ), @@ -40,6 +47,7 @@ ENDSTYLE; array( $code, $code ), array( $style, $style ), array( $textarea, $textarea ), + array( $pre, $pre ), ); } } diff --git a/tests/test-class-activitypub-mention.php b/tests/test-class-activitypub-mention.php index e4054d0..6f6b9ff 100644 --- a/tests/test-class-activitypub-mention.php +++ b/tests/test-class-activitypub-mention.php @@ -19,6 +19,12 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP { public function the_content_provider() { $code = 'hallo @username@example.org test'; + $pre = << +Please don't mention @username@example.org + here. + +ENDPRE; return array( array( 'hallo @username@example.org test', 'hallo @username test' ), array( 'hallo @pfefferle@notiz.blog test', 'hallo @pfefferle test' ), @@ -26,6 +32,7 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP { 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 ), + array( $pre, $pre ), ); }