Also protect <pre>

This commit is contained in:
Alex Kirk 2023-01-27 16:55:52 +01:00
parent cbfe6ea431
commit e7894f4c4a
4 changed files with 17 additions and 2 deletions

View file

@ -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[^>]*>.*?</\1[^>]*>#i',
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
function( $m ) use ( &$protected_tags ) {
$c = count( $protected_tags );
$protect = '!#!#PROTECT' . $c . '#!#!';

View file

@ -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[^>]*>.*?</\1[^>]*>#i',
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
function( $m ) use ( &$protected_tags ) {
$c = count( $protected_tags );
$protect = '!#!#PROTECT' . $c . '#!#!';

View file

@ -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;
]]>
</style>
ENDSTYLE;
$pre = <<<ENDPRE
<pre>
Please don't #touch
this.
</pre>
ENDPRE;
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
return array(
array( 'test', 'test' ),
@ -40,6 +47,7 @@ ENDSTYLE;
array( $code, $code ),
array( $style, $style ),
array( $textarea, $textarea ),
array( $pre, $pre ),
);
}
}

View file

@ -19,6 +19,12 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP {
public function the_content_provider() {
$code = 'hallo <code>@username@example.org</code> test';
$pre = <<<ENDPRE
<pre>
Please don't mention @username@example.org
here.
</pre>
ENDPRE;
return array(
array( 'hallo @username@example.org test', 'hallo <a rel="mention" class="u-url mention" href="https://example.org/users/username">@<span>username</span></a> test' ),
array( 'hallo @pfefferle@notiz.blog test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span></a> test' ),
@ -26,6 +32,7 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP {
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@pfefferle@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@pfefferle@notiz.blog</a> test' ),
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@pfefferle@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@pfefferle@notiz.blog</a> test' ),
array( $code, $code ),
array( $pre, $pre ),
);
}