diff options
| author | misskey-release-bot[bot] <157398866+misskey-release-bot[bot]@users.noreply.github.com> | 2025-12-06 12:22:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-06 12:22:58 +0000 |
| commit | e40c84f31df0202351c5585d3edbca000846b73b (patch) | |
| tree | 548eafb27b758c55de2e750a0ef9efbe3f056357 /packages/backend/src/misc/json-stringify-html-safe.ts | |
| parent | Merge pull request #16840 from misskey-dev/develop (diff) | |
| parent | Release: 2025.12.0 (diff) | |
| download | misskey-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.ts | 18 |
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]); +} |