diff options
-rw-r--r-- | src/config_mem.c | 10 | ||||
-rw-r--r-- | src/patch_parse.c | 21 | ||||
-rw-r--r-- | tests/config/snapshot.c | 17 | ||||
-rw-r--r-- | tests/patch/parse.c | 14 | ||||
-rw-r--r-- | tests/patch/patch_common.h | 12 |
5 files changed, 53 insertions, 21 deletions
diff --git a/src/config_mem.c b/src/config_mem.c index e4006db32..5b573a995 100644 --- a/src/config_mem.c +++ b/src/config_mem.c @@ -170,14 +170,6 @@ static int config_memory_unlock(git_config_backend *backend, int success) return config_error_readonly(); } -static int config_memory_snapshot(git_config_backend **out, git_config_backend *backend) -{ - GIT_UNUSED(out); - GIT_UNUSED(backend); - git_error_set(GIT_ERROR_CONFIG, "this backend does not support snapshots"); - return -1; -} - static void config_memory_free(git_config_backend *_backend) { config_memory_backend *backend = (config_memory_backend *)_backend; @@ -219,7 +211,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si backend->parent.iterator = config_memory_iterator; backend->parent.lock = config_memory_lock; backend->parent.unlock = config_memory_unlock; - backend->parent.snapshot = config_memory_snapshot; + backend->parent.snapshot = git_config_backend_snapshot; backend->parent.free = config_memory_free; *out = (git_config_backend *)backend; diff --git a/src/patch_parse.c b/src/patch_parse.c index 5032e35c8..1bf0190c3 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -69,27 +69,24 @@ static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t { int error; - if (!path_len) - return git_parse_err("patch contains empty path at line %"PRIuZ, - ctx->parse_ctx.line_num); - if ((error = git_buf_put(path, ctx->parse_ctx.line, path_len)) < 0) - goto done; + return error; git_parse_advance_chars(&ctx->parse_ctx, path_len); git_buf_rtrim(path); - if (path->size > 0 && path->ptr[0] == '"') - error = git_buf_unquote(path); - - if (error < 0) - goto done; + if (path->size > 0 && path->ptr[0] == '"' && + (error = git_buf_unquote(path)) < 0) + return error; git_path_squash_slashes(path); -done: - return error; + if (!path->size) + return git_parse_err("patch contains empty path at line %"PRIuZ, + ctx->parse_ctx.line_num); + + return 0; } static int parse_header_path(char **out, git_patch_parse_ctx *ctx) diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c index 3b90cfe49..5cc08a721 100644 --- a/tests/config/snapshot.c +++ b/tests/config/snapshot.c @@ -1,5 +1,7 @@ #include "clar_libgit2.h" +#include "config_backend.h" + static git_config *cfg; static git_config *snapshot; @@ -120,3 +122,18 @@ void test_config_snapshot__snapshot(void) cl_git_pass(p_unlink("configfile")); } + +void test_config_snapshot__snapshot_from_in_memony(void) +{ + const char *configuration = "[section]\nkey = 1\n"; + git_config_backend *backend; + int i; + + cl_git_pass(git_config_new(&cfg)); + cl_git_pass(git_config_backend_from_string(&backend, configuration, strlen(configuration))); + cl_git_pass(git_config_add_backend(cfg, backend, 0, NULL, 0)); + + cl_git_pass(git_config_snapshot(&snapshot, cfg)); + cl_git_pass(git_config_get_int32(&i, snapshot, "section.key")); + cl_assert_equal_i(i, 1); +} diff --git a/tests/patch/parse.c b/tests/patch/parse.c index 9067f4a9d..c18b63ab7 100644 --- a/tests/patch/parse.c +++ b/tests/patch/parse.c @@ -156,6 +156,20 @@ void test_patch_parse__binary_file_with_missing_paths(void) strlen(PATCH_BINARY_FILE_WITH_MISSING_PATHS), NULL)); } +void test_patch_parse__binary_file_with_whitespace_paths(void) +{ + git_patch *patch; + cl_git_fail(git_patch_from_buffer(&patch, PATCH_BINARY_FILE_WITH_WHITESPACE_PATHS, + strlen(PATCH_BINARY_FILE_WITH_WHITESPACE_PATHS), NULL)); +} + +void test_patch_parse__binary_file_with_empty_quoted_paths(void) +{ + git_patch *patch; + cl_git_fail(git_patch_from_buffer(&patch, PATCH_BINARY_FILE_WITH_QUOTED_EMPTY_PATHS, + strlen(PATCH_BINARY_FILE_WITH_QUOTED_EMPTY_PATHS), NULL)); +} + void test_patch_parse__memory_leak_on_multiple_paths(void) { git_patch *patch; diff --git a/tests/patch/patch_common.h b/tests/patch/patch_common.h index 153bab57f..4f2141dbe 100644 --- a/tests/patch/patch_common.h +++ b/tests/patch/patch_common.h @@ -912,6 +912,18 @@ "+++ \n" \ "Binary files " +#define PATCH_BINARY_FILE_WITH_WHITESPACE_PATHS \ + "diff --git a/file b/file\n" \ + "--- \n" \ + "+++ \n" \ + "Binary files " + +#define PATCH_BINARY_FILE_WITH_QUOTED_EMPTY_PATHS \ + "diff --git a/file b/file\n" \ + "--- \"\"\n" \ + "+++ \"\"\n" \ + "Binary files " + #define PATCH_MULTIPLE_OLD_PATHS \ "diff --git \n" \ "--- \n" \ |