diff options
Diffstat (limited to 'src/zen/frontend/html/util.js')
| -rw-r--r-- | src/zen/frontend/html/util.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/zen/frontend/html/util.js b/src/zen/frontend/html/util.js new file mode 100644 index 000000000..34241c9ae --- /dev/null +++ b/src/zen/frontend/html/util.js @@ -0,0 +1,16 @@ +// Copyright Epic Games, Inc. All Rights Reserved. +// Tiny shared helpers used across the trace-viewer modules. + +// Escape characters that have special meaning inside an HTML context (text or +// attribute) so that user-supplied strings can be safely interpolated into +// .innerHTML / template literals. Coerces the input to string first so callers +// don't have to. +export function escapeHtml(s) { + return String(s).replace(/[&<>"']/g, (c) => ({ + "&": "&", + "<": "<", + ">": ">", + "\"": """, + "'": "'", + }[c])); +} |