CoreFiles by mySites.guru
wp-sanitize.js51 lines, 1,043 bytes, from wordpress-5.1.21.zip
Raw History Compare with 5.1.20
md5
60dfe49df8846db04ec663ab443f9779
sha1
1b9e98e54716b9f96494303047c87ad1396542c2
sha256
abc3cd69f545b2145ff5b1a1cff06af3eecf5c14a5558373ec3207efc3f93bd2
/**
 * @output wp-includes/js/wp-sanitize.js
 */

( 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 || '';

			return text
				.replace( /<!--[\s\S]*?(-->|$)/g, '' )
				.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
				.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
		},

		/**
		 * Strip HTML tags and convert HTML entities.
		 *
		 * @param {string} text Text to strip tags and convert HTML entities.
		 *
		 * @return Sanitized text. False on failure.
		 */
		stripTagsAndEncodeText: function( text ) {
			var _text = wp.sanitize.stripTags( text ),
				textarea = document.createElement( 'textarea' );

			try {
				textarea.innerHTML = _text;
				_text = wp.sanitize.stripTags( textarea.value );
			} catch ( er ) {}

			return _text;
		}
	};
}() );

The same content is in 49 releases, WordPress 5.1-beta1 to 5.2.3-RC1. See them all, or every version of this file.