Skip to content

Commit

Permalink
Escape text implementation with both typeof checking and regex pretes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
aickin committed May 25, 2016
1 parent 6a3e9d5 commit 914e4e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/renderers/dom/shared/escapeTextContentForBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ function escaper(match) {
* @return {string} An escaped string.
*/
function escapeTextContentForBrowser(text) {
return ('' + text).replace(ESCAPE_REGEX, escaper);
switch (typeof text) {
case 'boolean':
case 'number':
// this shortcircuit helps perf for types that we know will never have
// special characters, especially given that this function is used often
// for numeric dom ids.
return '' + text;
default:
text = ('' + text);
if (ESCAPE_REGEX.test(text)) {
return text.replace(ESCAPE_REGEX, escaper);
}
return text;
}
}

module.exports = escapeTextContentForBrowser;

0 comments on commit 914e4e4

Please sign in to comment.