summaryrefslogtreecommitdiff
path: root/packages/backend/src/misc/json-stringify-html-safe.ts
diff options
context:
space:
mode:
authormisskey-release-bot[bot] <157398866+misskey-release-bot[bot]@users.noreply.github.com>2025-12-06 12:22:58 +0000
committerGitHub <noreply@github.com>2025-12-06 12:22:58 +0000
commite40c84f31df0202351c5585d3edbca000846b73b (patch)
tree548eafb27b758c55de2e750a0ef9efbe3f056357 /packages/backend/src/misc/json-stringify-html-safe.ts
parentMerge pull request #16840 from misskey-dev/develop (diff)
parentRelease: 2025.12.0 (diff)
downloadmisskey-e40c84f31df0202351c5585d3edbca000846b73b.tar.gz
misskey-e40c84f31df0202351c5585d3edbca000846b73b.tar.bz2
misskey-e40c84f31df0202351c5585d3edbca000846b73b.zip
Merge pull request #16916 from misskey-dev/develop
Release: 2025.12.0
Diffstat (limited to 'packages/backend/src/misc/json-stringify-html-safe.ts')
-rw-r--r--packages/backend/src/misc/json-stringify-html-safe.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/backend/src/misc/json-stringify-html-safe.ts b/packages/backend/src/misc/json-stringify-html-safe.ts
new file mode 100644
index 0000000000..aac12d57db
--- /dev/null
+++ b/packages/backend/src/misc/json-stringify-html-safe.ts
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+const ESCAPE_LOOKUP = {
+ '&': '\\u0026',
+ '>': '\\u003e',
+ '<': '\\u003c',
+ '\u2028': '\\u2028',
+ '\u2029': '\\u2029',
+} as Record<string, string>;
+
+const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
+
+export function htmlSafeJsonStringify(obj: any): string {
+ return JSON.stringify(obj).replace(ESCAPE_REGEX, x => ESCAPE_LOOKUP[x]);
+}