From 209b75f408192e0ebd6594951a8a9f94e82cdc2e Mon Sep 17 00:00:00 2001 From: "Konrad M." Date: Tue, 21 Apr 2026 21:51:04 +0200 Subject: [PATCH] feat(utils): add fmtLocation to normalize ICS LOCATION strings for display Strips RFC 5545 backslash-escapes (\n, \,, \;, \\) and collapses semicolons and newlines into comma-separated inline text. --- public/utils/html.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/public/utils/html.js b/public/utils/html.js index e825041..683c947 100644 --- a/public/utils/html.js +++ b/public/utils/html.js @@ -25,3 +25,25 @@ export function esc(str) { if (str == null) return ''; return String(str).replace(ESCAPE_RE, (ch) => ESCAPE_MAP[ch]); } + +/** + * Normalisiert einen iCalendar LOCATION-String fuer die Anzeige. + * Entfernt ICS-Backslash-Escapes (RFC 5545 §3.3.11) und fasst + * mehrzeilige Adressen zu einem einzeiligen String zusammen. + * + * @param {string|null|undefined} raw + * @returns {string} + */ +export function fmtLocation(raw) { + if (!raw) return ''; + return raw + .replace(/\\[Nn]/g, '\n') // \n / \N → newline + .replace(/\\,/g, ',') // \, → , + .replace(/\\;/g, ';') // \; → ; + .replace(/\\\\/g, '\\') // \\ → \ + .replace(/[\n\r;]+/g, ', ') // newlines / semicolons → ", " + .replace(/\s*,\s*/g, ', ') // normalize spaces around commas + .replace(/(?:,\s*){2,}/g, ', ') // collapse double commas + .replace(/ +/g, ' ') + .replace(/^[,\s]+|[,\s]+$/g, ''); // trim leading/trailing commas +}