Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
escape as html for default
Browse files Browse the repository at this point in the history
  • Loading branch information
popeindustries committed Sep 19, 2019
1 parent 5355258 commit bfb47b7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ const RE_SCRIPT_STYLE_TAG = /<\/(script|style)/gi;
*/
export function escape(string, context = 'text') {
switch (context) {
case 'text':
case 'attribute':
return string.replace(RE_HTML, (match) => HTML_ESCAPES[match]);
case 'script':
case 'style':
return string.replace(RE_SCRIPT_STYLE_TAG, '<\\/$1').replace(/<!--/g, '\\x3C!--');
case 'text':
case 'attribute':
default:
return string;
return string.replace(RE_HTML, (match) => HTML_ESCAPES[match]);
}
}

0 comments on commit bfb47b7

Please sign in to comment.