|
2 | 2 | * @output wp-includes/js/wp-sanitize.js |
3 | 3 | */ |
4 | 4 |
|
| 5 | +/* eslint-env es6 */ |
| 6 | + |
5 | 7 | ( function () { |
6 | 8 |
|
7 | 9 | window.wp = window.wp || {}; |
|
16 | 18 | /** |
17 | 19 | * Strip HTML tags. |
18 | 20 | * |
19 | | - * @param {string} text Text to strip the HTML tags from. |
| 21 | + * @param {string} text - Text to strip the HTML tags from. |
20 | 22 | * |
21 | | - * @return Stripped text. |
| 23 | + * @return {string} Stripped text. |
22 | 24 | */ |
23 | 25 | stripTags: function( text ) { |
24 | | - text = text || ''; |
| 26 | + let _text = text || ''; |
| 27 | + |
| 28 | + // Do the search-replace until there is nothing to be replaced. |
| 29 | + do { |
| 30 | + // Keep pre-replace text for comparison. |
| 31 | + text = _text; |
25 | 32 |
|
26 | | - // Do the replacement. |
27 | | - var _text = text |
| 33 | + // Do the replacement. |
| 34 | + _text = text |
28 | 35 | .replace( /<!--[\s\S]*?(-->|$)/g, '' ) |
29 | 36 | .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' ) |
30 | 37 | .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 | | - } |
| 38 | + } while ( _text !== text ); |
37 | 39 |
|
38 | 40 | // Return the text with stripped tags. |
39 | 41 | return _text; |
|
42 | 44 | /** |
43 | 45 | * Strip HTML tags and convert HTML entities. |
44 | 46 | * |
45 | | - * @param {string} text Text to strip tags and convert HTML entities. |
| 47 | + * @param {string} text - Text to strip tags and convert HTML entities. |
46 | 48 | * |
47 | | - * @return Sanitized text. False on failure. |
| 49 | + * @return {string} Sanitized text. |
48 | 50 | */ |
49 | 51 | stripTagsAndEncodeText: function( text ) { |
50 | | - var _text = wp.sanitize.stripTags( text ), |
| 52 | + let _text = wp.sanitize.stripTags( text ), |
51 | 53 | textarea = document.createElement( 'textarea' ); |
52 | 54 |
|
53 | 55 | try { |
|
0 commit comments