Protect cdata
This commit is contained in:
parent
e7894f4c4a
commit
6ea46c5024
3 changed files with 27 additions and 25 deletions
|
@ -44,24 +44,25 @@ class Hashtag {
|
|||
*/
|
||||
public static function the_content( $the_content ) {
|
||||
$protected_tags = array();
|
||||
$protect = function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
};
|
||||
$the_content = preg_replace_callback(
|
||||
'#<![CDATA[.*?]]>#is',
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
$the_content = preg_replace_callback(
|
||||
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||
function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
},
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
$the_content = preg_replace_callback(
|
||||
'#<[^>]+>#i',
|
||||
function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
},
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
|
||||
|
|
|
@ -24,24 +24,25 @@ class Mention {
|
|||
*/
|
||||
public static function the_content( $the_content ) {
|
||||
$protected_tags = array();
|
||||
$protect = function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
};
|
||||
$the_content = preg_replace_callback(
|
||||
'#<![CDATA[.*?]]>#is',
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
$the_content = preg_replace_callback(
|
||||
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||
function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
},
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
$the_content = preg_replace_callback(
|
||||
'#<a.*?href=[^>]+>.*?</a>#i',
|
||||
function( $m ) use ( &$protected_tags ) {
|
||||
$c = count( $protected_tags );
|
||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||
$protected_tags[ $protect ] = $m[0];
|
||||
return $protect;
|
||||
},
|
||||
$protect,
|
||||
$the_content
|
||||
);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase {
|
|||
$code = '<code>text with some #object and <a> tag inside</code>';
|
||||
$style = <<<ENDSTYLE
|
||||
<style type="text/css">
|
||||
<![[
|
||||
<![CDATA[
|
||||
color: #ccc;
|
||||
]]>
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue