Skip to content

Commit aa35091

Browse files
committed
Hoisted decode/encode regexps mentioned in #11537.
1 parent b31c91e commit aa35091

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

core/tools.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@
99
*/
1010

1111
( function() {
12+
1213
var functions = [],
1314
cssVendorPrefix =
1415
CKEDITOR.env.gecko ? '-moz-' :
1516
CKEDITOR.env.webkit ? '-webkit-' :
1617
CKEDITOR.env.ie ? '-ms-' :
17-
'';
18+
'',
19+
_ampRegex= /&/g,
20+
_gtRegex= />/g,
21+
_ltRegex= /</g,
22+
_quoteRegex= /"/g,
23+
24+
_ampEscRegex= /&amp;/g,
25+
_gtEscRegex= /&gt;/g,
26+
_ltEscRegex= /&lt;/g,
27+
_quoteEscRegex= /&quot;/g;
1828

1929
CKEDITOR.on( 'reset', function() {
2030
functions = [];
@@ -321,7 +331,7 @@
321331
* @returns {String} The encoded string.
322332
*/
323333
htmlEncode: function( text ) {
324-
return String( text ).replace( /&/g, '&amp;' ).replace( />/g, '&gt;' ).replace( /</g, '&lt;' );
334+
return String( text ).replace( _ampRegex, '&amp;' ).replace( _gtRegex, '&gt;' ).replace( _ltRegex, '&lt;' );
325335
},
326336

327337
/**
@@ -333,7 +343,7 @@
333343
* @returns {String} The decoded string.
334344
*/
335345
htmlDecode: function( text ) {
336-
return text.replace( /&amp;/g, '&' ).replace( /&gt;/g, '>' ).replace( /&lt;/g, '<' );
346+
return text.replace( _ampEscRegex, '&' ).replace( _gtEscRegex, '>' ).replace( _ltEscRegex, '<' );
337347
},
338348

339349
/**
@@ -345,7 +355,7 @@
345355
* @returns {String} The encoded value.
346356
*/
347357
htmlEncodeAttr: function( text ) {
348-
return text.replace( /"/g, '&quot;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' );
358+
return text.replace( _quoteRegex, '&quot;' ).replace( _ltRegex, '&lt;' ).replace( _gtRegex, '&gt;' );
349359
},
350360

351361
/**
@@ -359,7 +369,7 @@
359369
* @returns {String} The decoded text.
360370
*/
361371
htmlDecodeAttr: function( text ) {
362-
return text.replace( /&quot;/g, '"' ).replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' );
372+
return text.replace( _quoteEscRegex, '"' ).replace( _ltEscRegex, '<' ).replace( _gtEscRegex, '>' );
363373
},
364374

365375
/**

0 commit comments

Comments
 (0)