Skip to content

Commit e7894f4

Browse files
committed
Also protect <pre>
1 parent cbfe6ea commit e7894f4

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

includes/class-hashtag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function insert_post( $id, $post ) {
4545
public static function the_content( $the_content ) {
4646
$protected_tags = array();
4747
$the_content = preg_replace_callback(
48-
'#<(code|textarea|style)\b[^>]*>.*?</\1[^>]*>#i',
48+
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
4949
function( $m ) use ( &$protected_tags ) {
5050
$c = count( $protected_tags );
5151
$protect = '!#!#PROTECT' . $c . '#!#!';

includes/class-mention.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function init() {
2525
public static function the_content( $the_content ) {
2626
$protected_tags = array();
2727
$the_content = preg_replace_callback(
28-
'#<(code|textarea|style)\b[^>]*>.*?</\1[^>]*>#i',
28+
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
2929
function( $m ) use ( &$protected_tags ) {
3030
$c = count( $protected_tags );
3131
$protect = '!#!#PROTECT' . $c . '#!#!';

tests/test-class-activitypub-hashtag.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase {
55
*/
66
public function test_the_content( $content, $content_with_hashtag ) {
77
\wp_create_term( 'object', 'post_tag' );
8+
\wp_create_term( 'touch', 'post_tag' );
89
\wp_create_term( 'ccc', 'post_tag' );
910
$object = \get_term_by( 'name', 'object', 'post_tag' );
1011
$link = \get_term_link( $object, 'post_tag' );
@@ -23,6 +24,12 @@ public function the_content_provider() {
2324
]]>
2425
</style>
2526
ENDSTYLE;
27+
$pre = <<<ENDPRE
28+
<pre>
29+
Please don't #touch
30+
this.
31+
</pre>
32+
ENDPRE;
2633
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
2734
return array(
2835
array( 'test', 'test' ),
@@ -40,6 +47,7 @@ public function the_content_provider() {
4047
array( $code, $code ),
4148
array( $style, $style ),
4249
array( $textarea, $textarea ),
50+
array( $pre, $pre ),
4351
);
4452
}
4553
}

tests/test-class-activitypub-mention.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ public function test_the_content( $content, $content_with_mention ) {
1919

2020
public function the_content_provider() {
2121
$code = 'hallo <code>@[email protected]</code> test';
22+
$pre = <<<ENDPRE
23+
<pre>
24+
Please don't mention @[email protected]
25+
here.
26+
</pre>
27+
ENDPRE;
2228
return array(
2329
array( 'hallo @[email protected] test', 'hallo <a rel="mention" class="u-url mention" href="https://example.org/users/username">@<span>username</span></a> test' ),
2430
array( 'hallo @[email protected] test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span></a> test' ),
2531
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span>@notiz.blog</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@<span>pfefferle</span>@notiz.blog</a> test' ),
2632
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@[email protected]</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/author/matthias-pfefferle/">@[email protected]</a> test' ),
2733
array( 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@[email protected]</a> test', 'hallo <a rel="mention" class="u-url mention" href="https://notiz.blog/@pfefferle/">@[email protected]</a> test' ),
2834
array( $code, $code ),
35+
array( $pre, $pre ),
2936
);
3037
}
3138

0 commit comments

Comments
 (0)