Skip to content

Commit 7e46834

Browse files
committed
General: Update wp.sanitize.stripTags() to return empty string when not passed a string.
Developed in WordPress#10994 Follow-up to r61585, r61578. Props westonruter, jonsurrell, dmsnell, hugod. See #64574, #64274. git-svn-id: https://develop.svn.wordpress.org/trunk@61783 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a41f67e commit 7e46834

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/js/_enqueues/wp/sanitize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @return {string} Stripped text.
2424
*/
2525
stripTags: function( text ) {
26-
if ( ! text ) {
26+
if ( 'string' !== typeof text ) {
2727
return '';
2828
}
2929

tests/qunit/wp-includes/js/wp-sanitize.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ QUnit.test( 'stripTags should strip tags from string', function( assert ) {
1717
assert.strictEqual( result, 'Hello World', 'stripTags( "<p>Hello <b>World</b></p>" ) should return "Hello World"' );
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"' );
20+
QUnit.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

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

0 commit comments

Comments
 (0)