Make WordPress Core

Changeset 61783

Timestamp:
03/02/2026 07:50:05 PM (2 days ago)
Author:
westonruter
Message:

General: Update wp.sanitize.stripTags() to return empty string when not passed a string.

Developed in https://github.com/WordPress/wordpress-develop/pull/10994

Follow-up to r61585, r61578.

Props westonruter, jonsurrell, dmsnell, hugod.
See #64574, #64274.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/sanitize.js

    r61585 r61783  
    2424         */
    2525        stripTags: function( text ) {
    26             if ( ! text ) {
     26            if ( text ) {
    2727                return '';
    2828            }
  • trunk/tests/qunit/wp-includes/js/wp-sanitize.js

    r61585 r61783  
    1818} );
    1919
    20 QUnit.test( 'stripTags should convert numbers to strings', function( assert ) {
    21     const result = wp.sanitize.stripTags( 123 );
    22     assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' );
     20QUnit.test( 'stripTags should return empty string for truthy non-strings', function( assert ) {
     21    assert.strictEqual( wp.sanitize.stripTags( 123 ), '', 'stripTags( 123 ) should return ""' );
     22    assert.strictEqual( wp.sanitize.stripTags( true ), '', 'stripTags( true ) should return ""' );
     23    assert.strictEqual( wp.sanitize.stripTags( [ 6, 7 ] ), '', 'stripTags( [ 6, 7 ] ) should return ""' );
     24    assert.strictEqual( wp.sanitize.stripTags( { foo: 'bar' } ), '', 'stripTags( ( { foo: \'bar\' } ) should return ""' );
    2325} );
    2426
Note: See TracChangeset for help on using the changeset viewer.