Make WordPress Core

Changeset 61585


Ignore:
Timestamp:
02/03/2026 08:07:57 PM (8 weeks ago)
Author:
westonruter
Message:

General: Further preserve back-compat for wp.sanitize.stripTags() to return empty string when falsy value supplied.

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

Follow-up to [61578], [61347], [60907].

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

Location:
trunk
Files:
2 edited

Legend:

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

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

    r61578 r61585  
    2323} );
    2424
     25QUnit.test( 'stripTags should return empty string for input 0', function( assert ) {
     26    const result = wp.sanitize.stripTags( 0 );
     27    assert.strictEqual( result, '', 'stripTags( 0 ) should return ""' );
     28} );
     29
     30QUnit.test( 'stripTags should return "0" for input "0"', function( assert ) {
     31    const result = wp.sanitize.stripTags( '0' );
     32    assert.strictEqual( result, '0', 'stripTags( "0" ) should return "0"' );
     33} );
     34
     35QUnit.test( 'stripTags should return empty string for input false', function( assert ) {
     36    const result = wp.sanitize.stripTags( false );
     37    assert.strictEqual( result, '', 'stripTags( false ) should return ""' );
     38} );
     39
     40QUnit.test( 'stripTags should return empty string for input NaN', function( assert ) {
     41    const result = wp.sanitize.stripTags( NaN );
     42    assert.strictEqual( result, '', 'stripTags( NaN ) should return ""' );
     43} );
     44
     45QUnit.test( 'stripTags should return empty string for empty string input', function( assert ) {
     46    const result = wp.sanitize.stripTags( '' );
     47    assert.strictEqual( result, '', 'stripTags( "" ) should return ""' );
     48} );
     49
    2550QUnit.module( 'wp.sanitize.stripTagsAndEncodeText' );
    2651
Note: See TracChangeset for help on using the changeset viewer.