diff --git a/src/utils/escapeTextForBrowser.js b/src/utils/escapeTextForBrowser.js index 0eceb093a77..c06e6fbd0d5 100644 --- a/src/utils/escapeTextForBrowser.js +++ b/src/utils/escapeTextForBrowser.js @@ -20,11 +20,11 @@ "use strict"; var ESCAPE_LOOKUP = { - "&": "&", - ">": ">", - "<": "<", - "\"": """, - "'": "'" + '&': '&', + '>': '>', + '<': '<', + '"': '"', + "'": ''' }; var ESCAPE_REGEX = /[&><"']/g; @@ -40,7 +40,13 @@ function escaper(match) { * @return {string} An escaped string. */ function escapeTextForBrowser(text) { - return ('' + text).replace(ESCAPE_REGEX, escaper); + text = '' + text; + + if (ESCAPE_REGEX.test(text)) { + return text.replace(ESCAPE_REGEX, escaper); + } + + return text; } module.exports = escapeTextForBrowser;