diff --git a/src/js/_enqueues/wp/sanitize.js b/src/js/_enqueues/wp/sanitize.js index 7b69d65416ca5..515c27ce5ab23 100644 --- a/src/js/_enqueues/wp/sanitize.js +++ b/src/js/_enqueues/wp/sanitize.js @@ -23,7 +23,7 @@ * @return {string} Stripped text. */ stripTags: function( text ) { - if ( null === text || 'undefined' === typeof text ) { + if ( ! text ) { return ''; } diff --git a/tests/qunit/wp-includes/js/wp-sanitize.js b/tests/qunit/wp-includes/js/wp-sanitize.js index 45e687845925e..fe17e45833b77 100644 --- a/tests/qunit/wp-includes/js/wp-sanitize.js +++ b/tests/qunit/wp-includes/js/wp-sanitize.js @@ -22,6 +22,31 @@ QUnit.test( 'stripTags should convert numbers to strings', function( assert ) { assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' ); } ); +QUnit.test( 'stripTags should return empty string for input 0', function( assert ) { + const result = wp.sanitize.stripTags( 0 ); + assert.strictEqual( result, '', 'stripTags( 0 ) should return ""' ); +} ); + +QUnit.test( 'stripTags should return "0" for input "0"', function( assert ) { + const result = wp.sanitize.stripTags( '0' ); + assert.strictEqual( result, '0', 'stripTags( "0" ) should return "0"' ); +} ); + +QUnit.test( 'stripTags should return empty string for input false', function( assert ) { + const result = wp.sanitize.stripTags( false ); + assert.strictEqual( result, '', 'stripTags( false ) should return ""' ); +} ); + +QUnit.test( 'stripTags should return empty string for input NaN', function( assert ) { + const result = wp.sanitize.stripTags( NaN ); + assert.strictEqual( result, '', 'stripTags( NaN ) should return ""' ); +} ); + +QUnit.test( 'stripTags should return empty string for empty string input', function( assert ) { + const result = wp.sanitize.stripTags( '' ); + assert.strictEqual( result, '', 'stripTags( "" ) should return ""' ); +} ); + QUnit.module( 'wp.sanitize.stripTagsAndEncodeText' ); QUnit.test( 'stripTagsAndEncodeText should return empty string for null input', function( assert ) {