CoreFiles by mySites.guru
wp-sanitize.js47 lines, 993 bytes, from wordpress-4.9.21.zip
Raw History Compare with 4.9.20
md5
c82ddb34090cba66aff7d12291e75f21
sha1
d9fd55e429f511353caa5288748494aad6d7ea40
sha256
713a77ca5bfa233c2ef00f6fbaec078b3280a6125f4e0ce67b783858be71674f
( 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 101 releases, WordPress 4.9-beta1 to 5.0.32. See them all, or every version of this file.