diff --git a/src/mami.js/ui/messages.jsx b/src/mami.js/ui/messages.jsx index 3ce4bc3..88798bf 100644 --- a/src/mami.js/ui/messages.jsx +++ b/src/mami.js/ui/messages.jsx @@ -254,8 +254,13 @@ Umi.UI.Messages = (function() { continue; let offset = 0; - const parts = childNode.data.split(/([\p{White_Space}(){}\[\]<>'"]+)/u); - for(const part of parts) { + const parts = childNode.data.split(/([\p{White_Space}{}\[\]<>'"]+)/u); + for(let part of parts) { + while(part.startsWith('(') && part.endsWith(')')) { + offset += 1; + part = part.substring(1, part.length - 1); + } + const noProto = part.startsWith('//'); if(!noProto && !part.includes('://')) { offset += part.length; @@ -275,20 +280,20 @@ Umi.UI.Messages = (function() { offset = 0; } - let text = part; - while(!text.endsWith('/') && /\p{P}$/u.test(text)) - text = text.substring(0, text.length - 1); + const length = part.length; + while(!part.endsWith('/') && /\p{Po}$/u.test(part)) + part = part.substring(0, part.length - 1); - if(text.length < part.length) { - url = new URL(noProto ? (location.protocol + text) : text); - offset += part.length - text.length; + if(part.length < length) { + url = new URL(noProto ? (location.protocol + part) : part); + offset += length - part.length; } const replaceNode = childNode; - childNode = replaceNode.splitText(text.length); + childNode = replaceNode.splitText(part.length); replaceNode.replaceWith(<a class="markup__link" href={url.toString()} target="_blank" rel="nofollow noreferrer noopener"> - {decodeURI(text)} + {decodeURIComponent(part)} </a>); } } finally {