diff --git a/src/app/components/editor/output.test.ts b/src/app/components/editor/output.test.ts index 84b7e6cb4..cd8199c52 100644 --- a/src/app/components/editor/output.test.ts +++ b/src/app/components/editor/output.test.ts @@ -7,7 +7,7 @@ const roomWithMember = (userId: string, rawDisplayName: string): Room => ({ getMember: (id: string) => id === userId ? ({ userId: id, rawDisplayName } as never) : undefined, - }) as Room; + }) as unknown as Room; describe('toMatrixCustomHTML emoticons', () => { it('always serializes custom emoji images with height=32', () => { diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index 1e6fe39eb..33baeac15 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -30,7 +30,10 @@ const textToCustomHtml = (node: Text): string => sanitizeText(node.text); const markdownInlineLinkLabel = (label: string, fallback: string): string => { const t = label.trim(); if (!t) return fallback; - if (/[\]\n\r\u0000-\u001f]/.test(t)) return fallback; + if (t.includes(']')) return fallback; + for (let i = 0; i < t.length; i++) { + if (t.charCodeAt(i) <= 0x1f) return fallback; + } return t; }; diff --git a/src/app/components/message/content/ImageContent.tsx b/src/app/components/message/content/ImageContent.tsx index 13868c4bf..9904fa9f3 100644 --- a/src/app/components/message/content/ImageContent.tsx +++ b/src/app/components/message/content/ImageContent.tsx @@ -144,7 +144,7 @@ export const ImageContent = as<'div', ImageContentProps>( useEffect(() => { if (!viewer) { setViewerFullSrc(null); - return; + return undefined; } if ( typeof matrixThumbnailMaxEdge !== 'number' || @@ -152,7 +152,7 @@ export const ImageContent = as<'div', ImageContentProps>( encInfo || url.startsWith('http') ) { - return; + return undefined; } let cancelled = false; void (async () => { @@ -182,7 +182,9 @@ export const ImageContent = as<'div', ImageContentProps>( if (autoPlay) loadSrc(); }, [autoPlay, loadSrc]); - const hasDimensions = typeof info?.w === 'number' && typeof info?.h === 'number'; + const imageW = info?.w; + const imageH = info?.h; + const hasDimensions = typeof imageW === 'number' && typeof imageH === 'number'; const isContained = mediaLayout === 'contained'; const fillsSlot = Boolean(fillsPreviewSlot && isContained); const containedReserveStrip = @@ -200,7 +202,7 @@ export const ImageContent = as<'div', ImageContentProps>( : isContained ? { minHeight: containedReserveStrip ? toRem(stripMin) : undefined } : hasDimensions - ? { aspectRatio: `${info!.w} / ${info!.h}` } + ? { aspectRatio: `${imageW} / ${imageH}` } : { minHeight: '150px' }; const fillPreviewSlotStyle = fillsSlot diff --git a/src/app/plugins/markdown/expandBlockNewlines.ts b/src/app/plugins/markdown/expandBlockNewlines.ts index 617157be0..6c860744e 100644 --- a/src/app/plugins/markdown/expandBlockNewlines.ts +++ b/src/app/plugins/markdown/expandBlockNewlines.ts @@ -98,7 +98,7 @@ function looksLikeBlockStart(effective: string): boolean { if (/^[-*+]\s/.test(effective)) return true; if (/^\d{1,9}\.\s/.test(effective)) return true; if (/^(?:`{3,}|~{3,})/.test(effective)) return true; - if (/^\$\$/.test(effective)) return true; + if (effective.startsWith('$$')) return true; if (/^(?:-{3,}|\*{3,}|_{3,})\s*$/.test(effective)) return true; return false; diff --git a/src/app/plugins/markdown/markdownToHtml.ts b/src/app/plugins/markdown/markdownToHtml.ts index fcb28237d..74b680e11 100644 --- a/src/app/plugins/markdown/markdownToHtml.ts +++ b/src/app/plugins/markdown/markdownToHtml.ts @@ -78,7 +78,7 @@ const shieldBareMatrixToLinks = ( const unshieldBareMatrixToLinks = (html: string, placeholders: Map): string => { let result = html; - const keys = [...placeholders.keys()].sort((a, b) => b.length - a.length); + const keys = [...placeholders.keys()].toSorted((a, b) => b.length - a.length); for (const key of keys) { const url = placeholders.get(key); if (url) result = result.split(key).join(escapeHtml(url));