Commit 6a9ef012376e8a21dcfd0499ab16048eb6e954c3

Vicent Martí 2013-03-07T07:47:20

Merge pull request #1401 from carlosmn/leading-slash refs: explicitly catch leading slashes

diff --git a/src/refs.c b/src/refs.c
index 113cada..dd3dd64 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1667,6 +1667,9 @@ int git_reference__normalize_name(
 	process_flags = flags;
 	current = (char *)name;
 
+	if (*current == '/')
+		goto cleanup;
+
 	if (normalize)
 		git_buf_clear(buf);
 
diff --git a/tests-clar/refs/lookup.c b/tests-clar/refs/lookup.c
index 11fd68f..0dbebc5 100644
--- a/tests-clar/refs/lookup.c
+++ b/tests-clar/refs/lookup.c
@@ -32,6 +32,12 @@ void test_refs_lookup__with_resolve(void)
 	git_reference_free(a);
 }
 
+void test_refs_lookup__invalid_name(void)
+{
+	git_oid oid;
+	cl_git_fail(git_reference_name_to_id(&oid, g_repo, "/refs/tags/point_to_blob"));
+}
+
 void test_refs_lookup__oid(void)
 {
 	git_oid tag, expected;