2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-includes/js/wp-sanitize.js
|
|
|
|
*/
|
|
|
|
|
2017-07-15 11:48:46 -04:00
|
|
|
( function () {
|
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.sanitize
|
|
|
|
*
|
|
|
|
* Helper functions to sanitize strings.
|
|
|
|
*/
|
|
|
|
wp.sanitize = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip HTML tags.
|
|
|
|
*
|
|
|
|
* @param {string} text Text to have the HTML tags striped out of.
|
|
|
|
*
|
|
|
|
* @return Stripped text.
|
|
|
|
*/
|
|
|
|
stripTags: function( text ) {
|
|
|
|
text = text || '';
|
|
|
|
|
2019-09-04 13:13:21 -04:00
|
|
|
// Do the replacement.
|
|
|
|
var _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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the text with stripped tags.
|
|
|
|
return _text;
|
2017-07-15 11:48:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strip HTML tags and convert HTML entities.
|
|
|
|
*
|
|
|
|
* @param {string} text Text to strip tags and convert HTML entities.
|
|
|
|
*
|
|
|
|
* @return Sanitized text. False on failure.
|
|
|
|
*/
|
2017-10-04 14:58:47 -04:00
|
|
|
stripTagsAndEncodeText: function( text ) {
|
2017-09-14 15:29:44 -04:00
|
|
|
var _text = wp.sanitize.stripTags( text ),
|
2017-07-15 11:48:46 -04:00
|
|
|
textarea = document.createElement( 'textarea' );
|
|
|
|
|
|
|
|
try {
|
2019-09-04 13:13:21 -04:00
|
|
|
textarea.textContent = _text;
|
2017-09-14 15:29:44 -04:00
|
|
|
_text = wp.sanitize.stripTags( textarea.value );
|
2017-07-15 11:48:46 -04:00
|
|
|
} catch ( er ) {}
|
|
|
|
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}() );
|