Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-23 06:56:10 +0300
committerPatrick Steinhardt <ps@pks.im>2019-05-02 11:22:13 +0300
commit71424f634caea06215b8cfa61c6232d33201c168 (patch)
tree20f272ad724c9ed095d211d2eaf823df0fae7d60
parent4ec209cd753208ae745b7d9227a3752db950aca6 (diff)
patch_parse.c: Handle CRLF in parse_header_start
-rw-r--r--src/patch_parse.c3
-rw-r--r--tests/diff/parse.c19
-rw-r--r--tests/patch/patch_common.h9
3 files changed, 30 insertions, 1 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 545f1ca9e..d7311157f 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 7cc468245..a067861de 100644
--- a/tests/diff/parse.c
+++ b/tests/diff/parse.c
@@ -360,6 +360,7 @@ void test_diff_parse__lineinfo(void)
git_diff_free(diff);
}
+
void test_diff_parse__new_file_with_space(void)
{
const char *content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE;
@@ -377,3 +378,21 @@ void test_diff_parse__new_file_with_space(void)
git_patch_free(patch);
git_diff_free(diff);
}
+
+void test_diff_parse__crlf(void)
+{
+ const char *text = PATCH_CRLF;
+ 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);
+}
diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h
index 75aab4453..291ece9eb 100644
--- a/tests/patch/patch_common.h
+++ b/tests/patch/patch_common.h
@@ -850,3 +850,12 @@
"+++ b/sp ace.txt\n" \
"@@ -0,0 +1 @@\n" \
"+a\n"
+
+#define PATCH_CRLF \
+ "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"