Skip to content

Commit

Permalink
General: prevent antispambot() from breaking UTF8 strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnt committed Dec 2, 2024
1 parent 669bcce commit cef6fe4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,9 @@ function antispambot( $email_address, $hex_encoding = 0 ) {
for ( $i = 0, $len = strlen( $email_address ); $i < $len; $i++ ) {
$j = rand( 0, 1 + $hex_encoding );

if ( 0 === $j ) {
if ( ord( $email_address[ $i ] ) > 127 ) {
$email_no_spam_address .= $email_address[ $i ];
} elseif ( 0 === $j ) {
$email_no_spam_address .= '&#' . ord( $email_address[ $i ] ) . ';';
} elseif ( 1 === $j ) {
$email_no_spam_address .= $email_address[ $i ];
Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/tests/formatting/antispambot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @group formatting
*
* @covers ::antispambot
*/
class Tests_Formatting_antispambot extends WP_UnitTestCase {
public function test_returns_valid_utf8() {
$data = array(
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'info@grå.org',
'grå@grå.org',
"gr\u{0061}\u{030a}blå@grå.org",
'[email protected]',
);
foreach ( $data as $datum ) {
$this->assertTrue( seems_utf8( antispambot( $datum ) ) );
}
}
}

0 comments on commit cef6fe4

Please sign in to comment.