aboutsummaryrefslogtreecommitdiff
path: root/src/zen/frontend/html/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/zen/frontend/html/util.js')
-rw-r--r--src/zen/frontend/html/util.js16
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) => ({
+ "&": "&amp;",
+ "<": "&lt;",
+ ">": "&gt;",
+ "\"": "&quot;",
+ "'": "&#39;",
+ }[c]));
+}