From 323af4b1b55ea5b0f5d317ac7eb5279b660bc04f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 3 Feb 2026 11:03:47 -0800 Subject: [PATCH 1/4] Use non-strict equality check with null to cover undefined as well Co-authored-by: Jon Surrell --- src/js/_enqueues/wp/sanitize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/_enqueues/wp/sanitize.js b/src/js/_enqueues/wp/sanitize.js index 7b69d65416ca5..2ac45c81ab0ce 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 ( null == text ) { return ''; } From 6c902f0ea1aedf5190cd1369d807dfc1a23c61f7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 3 Feb 2026 11:18:02 -0800 Subject: [PATCH 2/4] Add edge cases for wp.sanitize.stripTags(). Adds QUnit tests for `wp.sanitize.stripTags()` with inputs `0` (number), `'0'` (string), and `''` (empty string) to ensure they are handled correctly and not treated as null/undefined. Co-authored-by: Hug0-Drelon <69580439+Hug0-Drelon@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/qunit/wp-includes/js/wp-sanitize.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/qunit/wp-includes/js/wp-sanitize.js b/tests/qunit/wp-includes/js/wp-sanitize.js index 45e687845925e..2233965aa3664 100644 --- a/tests/qunit/wp-includes/js/wp-sanitize.js +++ b/tests/qunit/wp-includes/js/wp-sanitize.js @@ -22,6 +22,21 @@ QUnit.test( 'stripTags should convert numbers to strings', function( assert ) { assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' ); } ); +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 "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 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 ) { From 6b47ff831255a19b97f851c56eae5123fd8a4027 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 3 Feb 2026 11:24:05 -0800 Subject: [PATCH 3/4] Add test for boolean false in wp.sanitize.stripTags(). Ensures that `wp.sanitize.stripTags( false )` returns the string "false", consistent with how non-null/undefined values are handled. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/qunit/wp-includes/js/wp-sanitize.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/qunit/wp-includes/js/wp-sanitize.js b/tests/qunit/wp-includes/js/wp-sanitize.js index 2233965aa3664..745357c123ee1 100644 --- a/tests/qunit/wp-includes/js/wp-sanitize.js +++ b/tests/qunit/wp-includes/js/wp-sanitize.js @@ -32,6 +32,11 @@ QUnit.test( 'stripTags should return "0" for input "0"', function( assert ) { assert.strictEqual( result, '0', 'stripTags( "0" ) should return "0"' ); } ); +QUnit.test( 'stripTags should return "false" for input false', function( assert ) { + const result = wp.sanitize.stripTags( false ); + assert.strictEqual( result, 'false', 'stripTags( false ) should return "false"' ); +} ); + QUnit.test( 'stripTags should return empty string for empty string input', function( assert ) { const result = wp.sanitize.stripTags( '' ); assert.strictEqual( result, '', 'stripTags( "" ) should return ""' ); From f7c8d79725a3f4f83a0df69c37f44b7cafb21c08 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 3 Feb 2026 11:34:31 -0800 Subject: [PATCH 4/4] Use falsy check in wp.sanitize.stripTags(). Updates `wp.sanitize.stripTags()` to return an empty string for all falsy values (0, false, NaN, etc.), restoring consistency with WordPress 6.9 behavior. Adds QUnit tests for these edge cases. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/js/_enqueues/wp/sanitize.js | 2 +- tests/qunit/wp-includes/js/wp-sanitize.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/js/_enqueues/wp/sanitize.js b/src/js/_enqueues/wp/sanitize.js index 2ac45c81ab0ce..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 ) { + if ( ! text ) { return ''; } diff --git a/tests/qunit/wp-includes/js/wp-sanitize.js b/tests/qunit/wp-includes/js/wp-sanitize.js index 745357c123ee1..fe17e45833b77 100644 --- a/tests/qunit/wp-includes/js/wp-sanitize.js +++ b/tests/qunit/wp-includes/js/wp-sanitize.js @@ -22,9 +22,9 @@ QUnit.test( 'stripTags should convert numbers to strings', function( assert ) { assert.strictEqual( result, '123', 'stripTags( 123 ) should return "123"' ); } ); -QUnit.test( 'stripTags should return "0" for input 0', function( assert ) { +QUnit.test( 'stripTags should return empty string for input 0', function( assert ) { const result = wp.sanitize.stripTags( 0 ); - assert.strictEqual( result, '0', 'stripTags( 0 ) should return "0"' ); + assert.strictEqual( result, '', 'stripTags( 0 ) should return ""' ); } ); QUnit.test( 'stripTags should return "0" for input "0"', function( assert ) { @@ -32,9 +32,14 @@ QUnit.test( 'stripTags should return "0" for input "0"', function( assert ) { assert.strictEqual( result, '0', 'stripTags( "0" ) should return "0"' ); } ); -QUnit.test( 'stripTags should return "false" for input false', function( assert ) { +QUnit.test( 'stripTags should return empty string for input false', function( assert ) { const result = wp.sanitize.stripTags( false ); - assert.strictEqual( result, 'false', 'stripTags( false ) should return "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 ) {