Skip to content

Commit 6ea46c5

Browse files
committed
Protect cdata
1 parent e7894f4 commit 6ea46c5

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

includes/class-hashtag.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,25 @@ public static function insert_post( $id, $post ) {
4444
*/
4545
public static function the_content( $the_content ) {
4646
$protected_tags = array();
47+
$protect = function( $m ) use ( &$protected_tags ) {
48+
$c = count( $protected_tags );
49+
$protect = '!#!#PROTECT' . $c . '#!#!';
50+
$protected_tags[ $protect ] = $m[0];
51+
return $protect;
52+
};
53+
$the_content = preg_replace_callback(
54+
'#<![CDATA[.*?]]>#is',
55+
$protect,
56+
$the_content
57+
);
4758
$the_content = preg_replace_callback(
4859
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
49-
function( $m ) use ( &$protected_tags ) {
50-
$c = count( $protected_tags );
51-
$protect = '!#!#PROTECT' . $c . '#!#!';
52-
$protected_tags[ $protect ] = $m[0];
53-
return $protect;
54-
},
60+
$protect,
5561
$the_content
5662
);
5763
$the_content = preg_replace_callback(
5864
'#<[^>]+>#i',
59-
function( $m ) use ( &$protected_tags ) {
60-
$c = count( $protected_tags );
61-
$protect = '!#!#PROTECT' . $c . '#!#!';
62-
$protected_tags[ $protect ] = $m[0];
63-
return $protect;
64-
},
65+
$protect,
6566
$the_content
6667
);
6768

includes/class-mention.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,25 @@ public static function init() {
2424
*/
2525
public static function the_content( $the_content ) {
2626
$protected_tags = array();
27+
$protect = function( $m ) use ( &$protected_tags ) {
28+
$c = count( $protected_tags );
29+
$protect = '!#!#PROTECT' . $c . '#!#!';
30+
$protected_tags[ $protect ] = $m[0];
31+
return $protect;
32+
};
33+
$the_content = preg_replace_callback(
34+
'#<![CDATA[.*?]]>#is',
35+
$protect,
36+
$the_content
37+
);
2738
$the_content = preg_replace_callback(
2839
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
29-
function( $m ) use ( &$protected_tags ) {
30-
$c = count( $protected_tags );
31-
$protect = '!#!#PROTECT' . $c . '#!#!';
32-
$protected_tags[ $protect ] = $m[0];
33-
return $protect;
34-
},
40+
$protect,
3541
$the_content
3642
);
3743
$the_content = preg_replace_callback(
3844
'#<a.*?href=[^>]+>.*?</a>#i',
39-
function( $m ) use ( &$protected_tags ) {
40-
$c = count( $protected_tags );
41-
$protect = '!#!#PROTECT' . $c . '#!#!';
42-
$protected_tags[ $protect ] = $m[0];
43-
return $protect;
44-
},
45+
$protect,
4546
$the_content
4647
);
4748

tests/test-class-activitypub-hashtag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function the_content_provider() {
1919
$code = '<code>text with some #object and <a> tag inside</code>';
2020
$style = <<<ENDSTYLE
2121
<style type="text/css">
22-
<![[
22+
<![CDATA[
2323
color: #ccc;
2424
]]>
2525
</style>

0 commit comments

Comments
 (0)