diff --git src/wp-admin/js/press-this.js src/wp-admin/js/press-this.js
index bf2e8300df..5d4d16546d 100644
|
|
|
8 | 8 | $window = $( window ), |
9 | 9 | $document = $( document ), |
10 | 10 | saveAlert = false, |
11 | | textarea = document.createElement( 'textarea' ), |
12 | 11 | sidebarIsOpen = false, |
13 | 12 | settings = window.wpPressThisConfig || {}, |
14 | 13 | data = window.wpPressThisData || {}, |
… |
… |
|
56 | 55 | } |
57 | 56 | |
58 | 57 | /** |
59 | | * Strips HTML tags |
60 | | * |
61 | | * @param string string Text to have the HTML tags striped out of. |
62 | | * @returns string Stripped text. |
63 | | */ |
64 | | function stripTags( string ) { |
65 | | string = string || ''; |
66 | | |
67 | | return string |
68 | | .replace( /<!--[\s\S]*?(-->|$)/g, '' ) |
69 | | .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' ) |
70 | | .replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' ); |
71 | | } |
72 | | |
73 | | /** |
74 | | * Strip HTML tags and convert HTML entities. |
75 | | * |
76 | | * @param text string Text. |
77 | | * @returns string Sanitized text. |
78 | | */ |
79 | | function sanitizeText( text ) { |
80 | | var _text = stripTags( text ); |
81 | | |
82 | | try { |
83 | | textarea.innerHTML = _text; |
84 | | _text = stripTags( textarea.value ); |
85 | | } catch ( er ) {} |
86 | | |
87 | | return _text; |
88 | | } |
89 | | |
90 | | /** |
91 | 58 | * Allow only HTTP or protocol relative URLs. |
92 | 59 | * |
93 | 60 | * @param url string The URL. |
… |
… |
|
97 | 64 | url = $.trim( url || '' ); |
98 | 65 | |
99 | 66 | if ( /^(?:https?:)?\/\//.test( url ) ) { |
100 | | url = stripTags( url ); |
| 67 | url = wp.sanitize.stripTags( url ); |
101 | 68 | return url.replace( /["\\]+/g, '' ); |
102 | 69 | } |
103 | 70 | |
… |
… |
|
224 | 191 | $image.replaceWith( $( '<span>' ).text( $image.attr( 'alt' ) ) ); |
225 | 192 | }); |
226 | 193 | |
227 | | return sanitizeText( $element.text() ); |
| 194 | return wp.sanitize.sanitizeText( $element.text() ); |
228 | 195 | } |
229 | 196 | |
230 | 197 | /** |
diff --git src/wp-includes/js/utils.js src/wp-includes/js/utils.js
index d8fa7d8d22..48e078ed24 100644
|
|
function getAllUserSettings() { |
195 | 195 | |
196 | 196 | return wpCookies.getHash( 'wp-settings-' + userSettings.uid ) || {}; |
197 | 197 | } |
| 198 | |
diff --git src/wp-includes/js/wp-sanitize.js src/wp-includes/js/wp-sanitize.js
new file mode 100644
index 0000000000..9add9b8e08
-
|
+
|
|
| 1 | ( function () { |
| 2 | |
| 3 | window.wp = window.wp || {}; |
| 4 | |
| 5 | /** |
| 6 | * wp.sanitize |
| 7 | * |
| 8 | * Helper functions to sanitize strings. |
| 9 | */ |
| 10 | wp.sanitize = { |
| 11 | |
| 12 | /** |
| 13 | * Strip HTML tags. |
| 14 | * |
| 15 | * @param {string} text Text to have the HTML tags striped out of. |
| 16 | * |
| 17 | * @return Stripped text. |
| 18 | */ |
| 19 | stripTags: function( text ) { |
| 20 | text = text || ''; |
| 21 | |
| 22 | return text |
| 23 | .replace( /<!--[\s\S]*?(-->|$)/g, '' ) |
| 24 | .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' ) |
| 25 | .replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' ); |
| 26 | }, |
| 27 | |
| 28 | /** |
| 29 | * Strip HTML tags and convert HTML entities. |
| 30 | * |
| 31 | * @param {string} text Text. |
| 32 | * |
| 33 | * @return Sanitized text. False on failure. |
| 34 | */ |
| 35 | sanitizeText: function( text ) { |
| 36 | var _text = wp.utils.stripTags( text ), |
| 37 | textarea = document.createElement( 'textarea' ); |
| 38 | |
| 39 | try { |
| 40 | textarea.innerHTML = _text; |
| 41 | _text = wp.utils.stripTags( textarea.value ); |
| 42 | } catch ( er ) {} |
| 43 | |
| 44 | return _text; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | }() ); |
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
index 7562e2839b..d39d28cdbc 100644
|
|
function wp_default_scripts( &$scripts ) { |
338 | 338 | ), |
339 | 339 | ) ); |
340 | 340 | |
| 341 | $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array('jquery'), false, 1 ); |
| 342 | |
341 | 343 | $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone', 'wp-util'), false, 1 ); |
342 | 344 | |
343 | 345 | $scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 ); |
… |
… |
function wp_default_scripts( &$scripts ) { |
576 | 578 | 'permalinkSaved' => __( 'Permalink saved' ), |
577 | 579 | ) ); |
578 | 580 | |
579 | | $scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 ); |
| 581 | $scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box', 'wp-sanitize' ), false, 1 ); |
580 | 582 | did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array( |
581 | 583 | 'newPost' => __( 'Title' ), |
582 | 584 | 'serverError' => __( 'Connection lost or the server is busy. Please try again later.' ), |