Skip to content
Open
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 ( ! text ) {
if ( 'string' !== typeof text ) {
return '';
}

Expand Down
8 changes: 5 additions & 3 deletions tests/qunit/wp-includes/js/wp-sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ QUnit.test( 'stripTags should strip tags from string', function( assert ) {
assert.strictEqual( result, 'Hello World', 'stripTags( "<p>Hello <b>World</b></p>" ) should return "Hello World"' );
} );

QUnit.test( 'stripTags should convert numbers to strings', function( assert ) {
const result = wp.sanitize.stripTags( 123 );
assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' );
QUnit.test( 'stripTags should return empty string for truthy non-strings', function( assert ) {
assert.strictEqual( wp.sanitize.stripTags( 123 ), '', 'stripTags( 123 ) should return ""' );
assert.strictEqual( wp.sanitize.stripTags( true ), '', 'stripTags( true ) should return ""' );
assert.strictEqual( wp.sanitize.stripTags( [ 6, 7 ] ), '', 'stripTags( [ 6, 7 ] ) should return ""' );
assert.strictEqual( wp.sanitize.stripTags( { foo: 'bar' } ), '', 'stripTags( ( { foo: \'bar\' } ) should return ""' );
} );

QUnit.test( 'stripTags should return empty string for input 0', function( assert ) {
Expand Down
Loading