Skip to content
Closed
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
30 changes: 16 additions & 14 deletions src/js/_enqueues/wp/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @output wp-includes/js/wp-sanitize.js
*/

/* eslint-env es6 */

( function () {

window.wp = window.wp || {};
Expand All @@ -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( /<!--[\s\S]*?(-->|$)/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;
Expand All @@ -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 {
Expand Down
Loading