Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/_enqueues/wp/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @return {string} Stripped text.
*/
stripTags: function( text ) {
if ( null === text || 'undefined' === typeof text ) {
if ( ! text ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's easier 😆

return '';
}

Expand Down
25 changes: 25 additions & 0 deletions tests/qunit/wp-includes/js/wp-sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Loading