~dricottone/huttese-apk

ref: 81d9b5e222c289ad1344f7282dbea7be9e1494c1 huttese-apk/sr.ht/libgit2/handle-crlf-in-parse_header_start.patch -rw-r--r-- 1.8 KiB
81d9b5e2 — Drew DeVault Update prometheus, alertmanager init scripts 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From 5e88f13eaa8ca30439b496066f6c57e608e18c4e Mon Sep 17 00:00:00 2001
From: Drew DeVault <sir@cmpwn.com>
Date: Fri, 22 Mar 2019 23:56:10 -0400
Subject: [PATCH] patch_parse.c: Handle CRLF in parse_header_start

---
 src/patch_parse.c  |  3 ++-
 tests/diff/parse.c | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/patch_parse.c b/src/patch_parse.c
index 647929fd5f..1182f19884 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -328,7 +328,8 @@ static int parse_header_start(git_patch_parsed *patch, git_patch_parse_ctx *ctx)
 	 * proceeed here. We then hope for the "---" and "+++" lines to fix that
 	 * for us.
 	 */
-	if (!git_parse_ctx_contains(&ctx->parse_ctx, "\n", 1)) {
+	if (!git_parse_ctx_contains(&ctx->parse_ctx, "\n", 1)
+			&& !git_parse_ctx_contains(&ctx->parse_ctx, "\r\n", 2)) {
 		git_parse_advance_chars(&ctx->parse_ctx, ctx->parse_ctx.line_len - 1);
 
 		git__free(patch->header_old_path);
diff --git a/tests/diff/parse.c b/tests/diff/parse.c
index 9cdaa92fbc..927ee90d80 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -359,3 +359,28 @@ void test_diff_parse__lineinfo(void)
 	git_patch_free(patch);
 	git_diff_free(diff);
 }
+
+void test_diff_parse__crlf(void)
+{
+	const char *text = "diff --git a/test-file b/test-file\r\n"
+	"new file mode 100644\r\n"
+	"index 0000000..af431f2 100644\r\n"
+	"--- /dev/null\r\n"
+	"+++ b/test-file\r\n"
+	"@@ -0,0 +1 @@\r\n"
+	"+a contents\r\n";
+
+	git_diff *diff;
+	git_patch *patch;
+	const git_diff_delta *delta;
+
+	cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+	cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+	delta = git_patch_get_delta(patch);
+
+	cl_assert_equal_s(delta->old_file.path, "test-file");
+	cl_assert_equal_s(delta->new_file.path, "test-file");
+
+	git_patch_free(patch);
+	git_diff_free(diff);
+}