Skip to content

Commit 4677c7a

Browse files
committed
General: Further preserve back-compat for wp.sanitize.stripTags() to return empty string when falsy value supplied.
Developed in WordPress#10856 Follow-up to [61578], [61347], [60907]. Props jonsurrell, hugod, westonruter. See #64274. Fixes #64574. git-svn-id: https://develop.svn.wordpress.org/trunk@61585 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 899dbce commit 4677c7a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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 ( null === text || 'undefined' === typeof text ) {
26+
if ( ! text ) {
2727
return '';
2828
}
2929

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ QUnit.test( 'stripTags should convert numbers to strings', function( assert ) {
2222
assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' );
2323
} );
2424

25+
QUnit.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+
30+
QUnit.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+
35+
QUnit.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+
40+
QUnit.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+
45+
QUnit.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+
2550
QUnit.module( 'wp.sanitize.stripTagsAndEncodeText' );
2651

2752
QUnit.test( 'stripTagsAndEncodeText should return empty string for null input', function( assert ) {

0 commit comments

Comments
 (0)