Skip to content

Commit dcff2e9

Browse files
MarcoDotIOclaude
andcommitted
fix(client-runtime): pull request bodies with CRLF line endings keep their code blocks whole
A body written in GitHub's web editor comes back with CRLF line endings. The fence pattern's `.` stops at the `\r`, so no fence in such a body was seen, and a media link or video tag on its own line inside a code block was lifted out as an attachment, cutting the block in two. A fence now matches with or without a trailing `\r`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1a3f76e commit dcff2e9

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎packages/client-runtime/src/pullRequestMarkdown.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ describe("pull request body segmentation", () => {
5959
]);
6060
});
6161

62+
// GitHub keeps CRLF in a body written in its web editor.
63+
it("recognizes fences in a body with CRLF line endings", () => {
64+
const body = "```\r\nhttps://example.com/demo.mp4\r\n```";
65+
expect(splitPullRequestBody(body)).toEqual([
66+
{ id: "markdown:0", kind: "markdown", text: body },
67+
]);
68+
});
69+
70+
it("closes a CRLF fence, so a video after it still lifts out", () => {
71+
const code = '```html\r\n<video src="https://example.com/example.mp4"></video>\r\n```';
72+
expect(splitPullRequestBody(`${code}\r\n\r\nhttps://example.com/demo.mp4\r\n`)).toEqual([
73+
{ id: "markdown:0", kind: "markdown", text: code },
74+
{
75+
id: "attachment:1",
76+
kind: "attachment",
77+
url: "https://example.com/demo.mp4",
78+
media: "video",
79+
},
80+
]);
81+
});
82+
6283
it("does not let a different fence marker close an open fence", () => {
6384
const body = "```\n~~~\nhttps://example.com/demo.mp4\n```";
6485
expect(splitPullRequestBody(body)).toEqual([

‎packages/client-runtime/src/pullRequestMarkdown.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export type PullRequestBodySegment =
1010
readonly media: "video" | "image" | "unknown";
1111
};
1212

13-
const FENCE_PATTERN = /^\s{0,3}((?:`{3,})|(?:~{3,}))(.*)$/u;
13+
// `.` stops at the `\r` of a CRLF body, which is how GitHub stores one written in its web editor.
14+
const FENCE_PATTERN = /^\s{0,3}((?:`{3,})|(?:~{3,}))(.*)\r?$/u;
1415
/**
1516
* How far a `<video>` tag may reach for its closing tag. Real embeds are one to three lines,
1617
* and the bound keeps an unclosed tag from making each one rescan the rest of the body.

0 commit comments

Comments
 (0)