Skip to content

Commit 5cf49d2

Browse files
fix(mobile): unclosed code fences in HTML blocks no longer freeze PR overviews (#26179)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0affd28 commit 5cf49d2

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎apps/mobile/src/lib/markdownDocument.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ function markdownHtmlTags(content: string): RegExpExecArray[] {
163163
}
164164
}
165165
if (closingIndex === -1) {
166-
if (fenced) codeRanges.push({ start: opening.index, end: content.length });
167-
continue;
166+
if (!fenced) continue;
167+
// An unclosed fence runs to the end of the content, so no later opener matters.
168+
codeRanges.push({ start: opening.index, end: content.length });
169+
break;
168170
}
169171
const closing = delimiters[closingIndex]!;
170172
codeRanges.push({ start: opening.index, end: closing.index + closing[0].length });

‎apps/mobile/src/lib/markdownHtml.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ describe("HTML in native Markdown", () => {
7575
expect(result).toContain('`<img src="inline.png">`');
7676
});
7777

78+
it("treats an unclosed fence in an HTML block as code through the end", () => {
79+
// Sized so the quadratic rescan cannot finish within the test timeout.
80+
const fences = Array.from({ length: 40_000 }, () => "```x y").join("\n");
81+
const markdown = `<details>\n<img src="before.png">\n${fences}\n<img src="after.png">\n</details>`;
82+
const result = markdownHtmlContent(markdown);
83+
expect(result).toContain("![](<before.png>)");
84+
expect(result).not.toContain("<details>");
85+
expect(result).toContain('<img src="after.png">\n</details>');
86+
});
87+
7888
it("links HTML anchors in a table cell without breaking the row at <br>", () => {
7989
const document = parseMarkdownDocument(
8090
"| Status | Preview URL |\n| - | - |\n| Done | <a href='https://commit.example.com'>Commit</a><br><a href='https://branch.example.com'>Branch</a> |",

0 commit comments

Comments
 (0)