Skip to content

Commit b058297

Browse files
author
Edward Thomson
committed
Merge pull request libgit2#3752 from libgit2/cmn/silly-tags
tag: ignore extra header fields
2 parents 512bd2c + eb39284 commit b058297

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/tag.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
137137

138138
tag->message = NULL;
139139
if (buffer < buffer_end) {
140-
if( *buffer != '\n' )
141-
return tag_error("No new line before message");
140+
/* If we're not at the end of the header, search for it */
141+
if( *buffer != '\n' ) {
142+
search = strstr(buffer, "\n\n");
143+
if (search)
144+
buffer = search + 1;
145+
else
146+
return tag_error("tag contains no message");
147+
}
142148

143149
text_len = buffer_end - ++buffer;
144150

tests/object/tag/read.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,40 @@ void test_object_tag_read__without_tagger_nor_message(void)
140140
git_tag_free(tag);
141141
git_repository_free(repo);
142142
}
143+
144+
static const char *silly_tag = "object c054ccaefbf2da31c3b19178f9e3ef20a3867924\n\
145+
type commit\n\
146+
tag v1_0_1\n\
147+
tagger Jamis Buck <jamis@37signals.com> 1107717917\n\
148+
diff --git a/lib/sqlite3/version.rb b/lib/sqlite3/version.rb\n\
149+
index 0b3bf69..4ee8fc2 100644\n\
150+
--- a/lib/sqlite3/version.rb\n\
151+
+++ b/lib/sqlite3/version.rb\n\
152+
@@ -36,7 +36,7 @@ module SQLite3\n\
153+
\n\
154+
MAJOR = 1\n\
155+
MINOR = 0\n\
156+
- TINY = 0\n\
157+
+ TINY = 1\n\
158+
\n\
159+
STRING = [ MAJOR, MINOR, TINY ].join( \".\" )\n\
160+
\n\
161+
-0600\n\
162+
\n\
163+
v1_0_1 release\n";
164+
165+
void test_object_tag_read__extra_header_fields(void)
166+
{
167+
git_tag *tag;
168+
git_odb *odb;
169+
git_oid id;
170+
171+
cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
172+
173+
cl_git_pass(git_odb_write(&id, odb, silly_tag, strlen(silly_tag), GIT_OBJ_TAG));
174+
cl_git_pass(git_tag_lookup(&tag, g_repo, &id));
175+
176+
cl_assert_equal_s("v1_0_1 release\n", git_tag_message(tag));
177+
178+
git_tag_free(tag);
179+
}

0 commit comments

Comments
 (0)