Skip to content

Commit 4821696

Browse files
MarcoDotIOclaudemaria-rcks
authored
fix(client-runtime): pull request bodies with CRLF line endings keep their code blocks whole (pingdotgg#30352)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 43dfdcc commit 4821696

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
@@ -80,6 +80,27 @@ describe("pull request body segmentation", () => {
8080
]);
8181
});
8282

83+
// GitHub keeps CRLF in a body written in its web editor.
84+
it("recognizes fences in a body with CRLF line endings", () => {
85+
const body = "```\r\nhttps://example.com/demo.mp4\r\n```";
86+
expect(splitPullRequestBody(body)).toEqual([
87+
{ id: "markdown:0", kind: "markdown", text: body, sourceOffset: 0 },
88+
]);
89+
});
90+
91+
it("closes a CRLF fence, so a video after it still lifts out", () => {
92+
const code = '```html\r\n<video src="https://example.com/example.mp4"></video>\r\n```';
93+
expect(splitPullRequestBody(`${code}\r\n\r\nhttps://example.com/demo.mp4\r\n`)).toEqual([
94+
{ id: "markdown:0", kind: "markdown", text: code, sourceOffset: 0 },
95+
{
96+
id: "attachment:1",
97+
kind: "attachment",
98+
url: "https://example.com/demo.mp4",
99+
media: "video",
100+
},
101+
]);
102+
});
103+
83104
it("does not let a different fence marker close an open fence", () => {
84105
const body = "```\n~~~\nhttps://example.com/demo.mp4\n```";
85106
expect(splitPullRequestBody(body)).toEqual([

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

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

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

0 commit comments

Comments
 (0)