fix: normalize CHRNX unicode titles

This commit is contained in:
chrnx committed 2026-08-11 16:12:36 -05:00
1 parent a769228c01
commit 0226a52119
6 files changed
+67 -10

No files matched your search

+42
View File
@@ -298,6 +298,48 @@ class EditorialQueriesTest extends WP_UnitTestCase {
$this->assertFalse( chrnx_is_eligible_editorial_post( $post ) );
$post->post_title = "\fX";
$this->assertTrue( chrnx_is_eligible_editorial_post( $post ) );
$post->post_title = "\xC3\x28";
$this->assertFalse( chrnx_is_eligible_editorial_post( $post ), 'Invalid UTF-8 fails closed.' );
}
/** Unicode whitespace eligibility agrees between canonical PHP and the real database query. */
public function test_unicode_title_eligibility_matches_database_matrix_without_underfill() {
$cases = array(
'ascii spaces' => array( ' ', false ),
'control spaces' => array( "\t\n\f", false ),
'nbsp' => array( "\u{00A0}", false ),
'em space' => array( "\u{2003}", false ),
'mixed whitespace' => array( " \t\u{00A0}\u{2003}", false ),
'ascii content' => array( " \tA", true ),
'nbsp with content' => array( "\u{00A0}A", true ),
'em with unicode' => array( "\u{2003}字", true ),
'mixed with text' => array( "\u{00A0}\u{2003} x", true ),
);
$expected_ids = array();
$all_ids = array();
foreach ( $cases as $label => $case ) {
$post_id = $this->create_post( $case[0], '2026-06-08 10:00:00' );
$all_ids[] = $post_id;
$this->assertSame( $case[1], chrnx_is_eligible_editorial_post( $post_id ), $label . ' PHP eligibility' );
if ( $case[1] ) {
$expected_ids[] = $post_id;
}
}
$query = chrnx_run_eligible_query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $all_ids,
'posts_per_page' => count( $all_ids ),
'fields' => 'ids',
'orderby' => 'ID',
'order' => 'ASC',
'chrnx_require_nonempty_title' => true,
)
);
$this->assertSame( $expected_ids, array_map( 'absint', $query->posts ) );
$this->assertCount( 3, chrnx_get_featured_story_ids( 3 ) );
}
/** Journal and Show SQL use the same literal stored-title contract as PHP. */