Skip to content

Commit 533ff0d

Browse files
committed
General: prevent antispambot() from breaking UTF8 strings.
1 parent 088aced commit 533ff0d

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/wp-includes/formatting.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,9 @@ function antispambot( $email_address, $hex_encoding = 0 ) {
30273027
for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) {
30283028
$j = rand( 0, 1 + $hex_encoding );
30293029

3030-
if ( 0 === $j ) {
3030+
if ( ord( $email_address[ $i ] ) > 127 ) {
3031+
$email_no_spam_address .= $email_address[ $i ];
3032+
} elseif ( 0 === $j ) {
30313033
$email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';';
30323034
} elseif ( 1 === $j ) {
30333035
$email_no_spam_address .= $email_address[ $i ];
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* @group formatting
5+
*
6+
* @covers ::antispambot
7+
*/
8+
class Tests_Formatting_antispambot extends WP_UnitTestCase {
9+
public function test_returns_valid_utf8() {
10+
$data = array(
11+
12+
13+
14+
15+
16+
17+
'info@grå.org',
18+
'grå@grå.org',
19+
"gr\u{0061}\u{030a}blå@grå.org",
20+
21+
);
22+
foreach ( $data as $datum ) {
23+
$this->assertTrue( seems_utf8( antispambot( $datum ) ) );
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)