fix(diagnostic): Nachricht mit URL+Satzzeichen verschwand im Chat

linkifyText nahm Satzzeichen am Ende mit in die URL ("(http://host:8080),")
und new URL() warf "Invalid URL" -- die ganze Bubble wurde nicht gerendert.
Satzzeichen am Ende abtrennen (Klammer bleibt, wenn die URL sie selbst oeffnet),
ungueltige URLs bleiben Text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-03 09:01:07 +01:00
co-authored by Claude Opus 5.5
parent 9b25187084
commit f28c0e2b90
+16 -6
View File
@@ -3558,16 +3558,26 @@
function linkifyText(escaped) {
// URLs in escaped HTML erkennen und ersetzen
return escaped.replace(/(https?:\/\/[^\s<&]+)/g, function(url) {
const decoded = url.replace(/&amp;/g, '&');
const pathname = new URL(decoded).pathname;
return escaped.replace(/(https?:\/\/[^\s<&]+)/g, function(match) {
// Satzzeichen am Ende gehoeren nicht zur URL: "(http://host:8080)," —
// sonst wirft new URL() und die ganze Nachricht wird nicht angezeigt.
let url = match, rest = '';
while (/[.,;:!?)\]'"]$/.test(url)) {
// ")" gehoert zur URL, wenn sie selbst eine "(" offen hat (Wikipedia)
if (url.endsWith(')') && url.split('(').length >= url.split(')').length) break;
rest = url.slice(-1) + rest;
url = url.slice(0, -1);
}
let pathname;
try { pathname = new URL(url.replace(/&amp;/g, '&')).pathname; }
catch (e) { return match; } // keine gueltige URL: als Text lassen
if (MEDIA_IMG.test(pathname)) {
return `<a href="${url}" target="_blank">${url}</a><img src="${url}" class="chat-media" onclick="event.stopPropagation();openLightbox('img','${url}')">`;
return `<a href="${url}" target="_blank">${url}</a><img src="${url}" class="chat-media" onclick="event.stopPropagation();openLightbox('img','${url}')">` + rest;
}
if (MEDIA_VID.test(pathname)) {
return `<a href="${url}" target="_blank">${url}</a><video src="${url}" class="chat-media" controls onclick="event.stopPropagation();openLightbox('video','${url}')"></video>`;
return `<a href="${url}" target="_blank">${url}</a><video src="${url}" class="chat-media" controls onclick="event.stopPropagation();openLightbox('video','${url}')"></video>` + rest;
}
return `<a href="${url}" target="_blank" rel="noopener">${url}</a>`;
return `<a href="${url}" target="_blank" rel="noopener">${url}</a>` + rest;
});
}