Also protect <pre>
This commit is contained in:
parent
cbfe6ea431
commit
e7894f4c4a
4 changed files with 17 additions and 2 deletions
|
@ -45,7 +45,7 @@ class Hashtag {
|
||||||
public static function the_content( $the_content ) {
|
public static function the_content( $the_content ) {
|
||||||
$protected_tags = array();
|
$protected_tags = array();
|
||||||
$the_content = preg_replace_callback(
|
$the_content = preg_replace_callback(
|
||||||
'#<(code|textarea|style)\b[^>]*>.*?</\1[^>]*>#i',
|
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||||
function( $m ) use ( &$protected_tags ) {
|
function( $m ) use ( &$protected_tags ) {
|
||||||
$c = count( $protected_tags );
|
$c = count( $protected_tags );
|
||||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Mention {
|
||||||
public static function the_content( $the_content ) {
|
public static function the_content( $the_content ) {
|
||||||
$protected_tags = array();
|
$protected_tags = array();
|
||||||
$the_content = preg_replace_callback(
|
$the_content = preg_replace_callback(
|
||||||
'#<(code|textarea|style)\b[^>]*>.*?</\1[^>]*>#i',
|
'#<(pre|code|textarea|style)\b[^>]*>.*?</\1[^>]*>#is',
|
||||||
function( $m ) use ( &$protected_tags ) {
|
function( $m ) use ( &$protected_tags ) {
|
||||||
$c = count( $protected_tags );
|
$c = count( $protected_tags );
|
||||||
$protect = '!#!#PROTECT' . $c . '#!#!';
|
$protect = '!#!#PROTECT' . $c . '#!#!';
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Test_Activitypub_Hashtag extends WP_UnitTestCase {
|
||||||
*/
|
*/
|
||||||
public function test_the_content( $content, $content_with_hashtag ) {
|
public function test_the_content( $content, $content_with_hashtag ) {
|
||||||
\wp_create_term( 'object', 'post_tag' );
|
\wp_create_term( 'object', 'post_tag' );
|
||||||
|
\wp_create_term( 'touch', 'post_tag' );
|
||||||
\wp_create_term( 'ccc', 'post_tag' );
|
\wp_create_term( 'ccc', 'post_tag' );
|
||||||
$object = \get_term_by( 'name', 'object', 'post_tag' );
|
$object = \get_term_by( 'name', 'object', 'post_tag' );
|
||||||
$link = \get_term_link( $object, 'post_tag' );
|
$link = \get_term_link( $object, 'post_tag' );
|
||||||
|
@ -23,6 +24,12 @@ color: #ccc;
|
||||||
]]>
|
]]>
|
||||||
</style>
|
</style>
|
||||||
ENDSTYLE;
|
ENDSTYLE;
|
||||||
|
$pre = <<<ENDPRE
|
||||||
|
<pre>
|
||||||
|
Please don't #touch
|
||||||
|
this.
|
||||||
|
</pre>
|
||||||
|
ENDPRE;
|
||||||
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
|
$textarea = '<textarea name="test" rows="20">color: #ccc</textarea>';
|
||||||
return array(
|
return array(
|
||||||
array( 'test', 'test' ),
|
array( 'test', 'test' ),
|
||||||
|
@ -40,6 +47,7 @@ ENDSTYLE;
|
||||||
array( $code, $code ),
|
array( $code, $code ),
|
||||||
array( $style, $style ),
|
array( $style, $style ),
|
||||||
array( $textarea, $textarea ),
|
array( $textarea, $textarea ),
|
||||||
|
array( $pre, $pre ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@ class Test_Activitypub_Mention extends ActivityPub_TestCase_Cache_HTTP {
|
||||||
|
|
||||||
public function the_content_provider() {
|
public function the_content_provider() {
|
||||||
$code = 'hallo <code>@username@example.org</code> test';
|
$code = 'hallo <code>@username@example.org</code> test';
|
||||||
|
$pre = <<<ENDPRE
|
||||||
|
<pre>
|
||||||
|
Please don't mention @username@example.org
|
||||||
|
here.
|
||||||
|
</pre>
|
||||||
|
ENDPRE;
|
||||||
return array(
|
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 @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' ),
|
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/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( '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( $code, $code ),
|
||||||
|
array( $pre, $pre ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue