diff --git a/inc/queries.php b/inc/queries.php
index d4d3d62..dc6379c 100644
--- a/inc/queries.php
+++ b/inc/queries.php
@@ -17,7 +17,7 @@ function chrnx_is_eligible_editorial_post( $post ) {
return $post instanceof WP_Post
&& 'post' === $post->post_type
&& 'publish' === $post->post_status
- && '' !== trim( wp_strip_all_tags( $post->post_title ) );
+ && 1 === preg_match( '/[^[:space:]]/', $post->post_title );
}
/** Clear request-local editorial query results after relevant mutations. */
@@ -76,8 +76,7 @@ function chrnx_filter_nonempty_editorial_titles( $where, $query ) {
}
global $wpdb;
- $visible_text_pattern = '(^|>)[[:space:]]*[^<[:space:]][^<]*(<|$)';
- return $where . $wpdb->prepare( ' AND ' . $wpdb->posts . '.post_title REGEXP %s', $visible_text_pattern );
+ return $where . $wpdb->prepare( ' AND ' . $wpdb->posts . '.post_title REGEXP %s', '[^[:space:]]' );
}
/**
@@ -138,7 +137,7 @@ function chrnx_get_eligible_editorial_post_ids( $extra_args = array() ) {
}
$query = chrnx_run_eligible_query( $args );
- $ids = array_values( array_map( 'absint', array_filter( $query->posts, 'chrnx_is_eligible_editorial_post' ) ) );
+ $ids = array_values( array_map( 'absint', $query->posts ) );
if ( ! empty( $ids ) ) {
_prime_post_caches( $ids, true, true );
}
diff --git a/tests/php/BlockRenderingTest.php b/tests/php/BlockRenderingTest.php
index 1f16ad7..2eeb971 100644
--- a/tests/php/BlockRenderingTest.php
+++ b/tests/php/BlockRenderingTest.php
@@ -172,6 +172,26 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( 'placeholder', strtolower( $output ) );
}
+ /** Stored title markup is displayed literally and cannot inject executable elements. */
+ public function test_editorial_cards_escape_stored_title_markup() {
+ $title = '';
+ $post_id = self::factory()->post->create( array( 'post_title' => $title ) );
+ $output = render_block(
+ array(
+ 'blockName' => 'chrnx/featured-stories',
+ 'attrs' => array( 'limit' => 1 ),
+ 'innerBlocks' => array(),
+ 'innerHTML' => '',
+ 'innerContent' => array(),
+ )
+ );
+
+ $this->assertSame( $post_id, chrnx_get_featured_story_ids( 1 )[0] );
+ $this->assertStringContainsString( esc_html( get_the_title( $post_id ) ), $output );
+ $this->assertStringNotContainsString( '