diff --git a/src/js/_enqueues/wp/sanitize.js b/src/js/_enqueues/wp/sanitize.js index 13f9045024f74..4252d0a014f7a 100644 --- a/src/js/_enqueues/wp/sanitize.js +++ b/src/js/_enqueues/wp/sanitize.js @@ -2,6 +2,8 @@ * @output wp-includes/js/wp-sanitize.js */ +/* eslint-env es6 */ + ( function () { window.wp = window.wp || {}; @@ -16,24 +18,24 @@ /** * Strip HTML tags. * - * @param {string} text Text to strip the HTML tags from. + * @param {string} text - Text to strip the HTML tags from. * - * @return Stripped text. + * @return {string} Stripped text. */ stripTags: function( text ) { - text = text || ''; + let _text = text || ''; + + // Do the search-replace until there is nothing to be replaced. + do { + // Keep pre-replace text for comparison. + text = _text; - // Do the replacement. - var _text = text + // Do the replacement. + _text = text .replace( /|$)/g, '' ) .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' ) .replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' ); - - // If the initial text is not equal to the modified text, - // do the search-replace again, until there is nothing to be replaced. - if ( _text !== text ) { - return wp.sanitize.stripTags( _text ); - } + } while ( _text !== text ); // Return the text with stripped tags. return _text; @@ -42,12 +44,12 @@ /** * Strip HTML tags and convert HTML entities. * - * @param {string} text Text to strip tags and convert HTML entities. + * @param {string} text - Text to strip tags and convert HTML entities. * - * @return Sanitized text. False on failure. + * @return {string} Sanitized text. */ stripTagsAndEncodeText: function( text ) { - var _text = wp.sanitize.stripTags( text ), + let _text = wp.sanitize.stripTags( text ), textarea = document.createElement( 'textarea' ); try {