wp/wp-includes/js/wp-sanitize.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 22 8c2e4d02f4ef
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
       
     1 /**
       
     2  * @output wp-includes/js/wp-sanitize.js
       
     3  */
       
     4 
     1 ( function () {
     5 ( function () {
     2 
     6 
     3 	window.wp = window.wp || {};
     7 	window.wp = window.wp || {};
     4 
     8 
     5 	/**
     9 	/**
    17 		 * @return  Stripped text.
    21 		 * @return  Stripped text.
    18 		 */
    22 		 */
    19 		stripTags: function( text ) {
    23 		stripTags: function( text ) {
    20 			text = text || '';
    24 			text = text || '';
    21 
    25 
    22 			return text
    26 			// Do the replacement.
    23 				.replace( /<!--[\s\S]*?(-->|$)/g, '' )
    27 			var _text = text
    24 				.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
    28 					.replace( /<!--[\s\S]*?(-->|$)/g, '' )
    25 				.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
    29 					.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
       
    30 					.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
       
    31 
       
    32 			// If the initial text is not equal to the modified text,
       
    33 			// do the search-replace again, until there is nothing to be replaced.
       
    34 			if ( _text !== text ) {
       
    35 				return wp.sanitize.stripTags( _text );
       
    36 			}
       
    37 
       
    38 			// Return the text with stripped tags.
       
    39 			return _text;
    26 		},
    40 		},
    27 
    41 
    28 		/**
    42 		/**
    29 		 * Strip HTML tags and convert HTML entities.
    43 		 * Strip HTML tags and convert HTML entities.
    30 		 *
    44 		 *
    35 		stripTagsAndEncodeText: function( text ) {
    49 		stripTagsAndEncodeText: function( text ) {
    36 			var _text = wp.sanitize.stripTags( text ),
    50 			var _text = wp.sanitize.stripTags( text ),
    37 				textarea = document.createElement( 'textarea' );
    51 				textarea = document.createElement( 'textarea' );
    38 
    52 
    39 			try {
    53 			try {
    40 				textarea.innerHTML = _text;
    54 				textarea.textContent = _text;
    41 				_text = wp.sanitize.stripTags( textarea.value );
    55 				_text = wp.sanitize.stripTags( textarea.value );
    42 			} catch ( er ) {}
    56 			} catch ( er ) {}
    43 
    57 
    44 			return _text;
    58 			return _text;
    45 		}
    59 		}