From e5ef0f18141409fc932d2c9cc0a42b769a880927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 31 Jan 2013 20:23:30 +0100 Subject: [PATCH] refs: handle ALLOW_ONELEVEL normalization with leading slash A leading slash confuses the name normalization code when the flags include ALLOW_ONELEVEL. Catch this case in particular to avoid triggering an assertion in the uppercase check which expects us not to pass it an empty string. The existing tests don't catch this as they simply use the NORMAL flag. This fixes #1300. --- src/refs.c | 5 +++++ tests-clar/refs/isvalidname.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/refs.c b/src/refs.c index 52e0adac6..e75f51001 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1691,6 +1691,11 @@ int git_reference__normalize_name( segments_count++; } + /* This means that there's a leading slash in the refname */ + if (segment_len == 0 && segments_count == 0) { + goto cleanup; + } + if (current[segment_len] == '\0') break; diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c index 3cc838d34..b61a02360 100644 --- a/tests-clar/refs/isvalidname.c +++ b/tests-clar/refs/isvalidname.c @@ -10,6 +10,8 @@ void test_refs_isvalidname__can_detect_invalid_formats(void) cl_assert_equal_i(false, git_reference_is_valid_name("_NO_LEADING_UNDERSCORE")); cl_assert_equal_i(false, git_reference_is_valid_name("HEAD/aa")); cl_assert_equal_i(false, git_reference_is_valid_name("lower_case")); + cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master")); + cl_assert_equal_i(false, git_reference_is_valid_name("/")); cl_assert_equal_i(false, git_reference_is_valid_name("")); }