Skip to content

Commit 15df841

Browse files
committed
Merge branch 'jk/ref-filter-parsing-bugs'
Various tests exercising the transfer.credentialsInUrl configuration are taught to avoid making requests which require resolving localhost to reduce CI-flakiness. * jk/ref-filter-parsing-bugs: ref-filter: fix parsing of signatures with CRLF and no body ref-filter: fix parsing of signatures without blank lines
2 parents 4b6302c + 8e1c5fc commit 15df841

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

ref-filter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,12 +1375,12 @@ static void find_subpos(const char *buf,
13751375
/* subject is first non-empty line */
13761376
*sub = buf;
13771377
/* subject goes to first empty line before signature begins */
1378-
if ((eol = strstr(*sub, "\n\n"))) {
1378+
if ((eol = strstr(*sub, "\n\n")) ||
1379+
(eol = strstr(*sub, "\r\n\r\n"))) {
13791380
eol = eol < sigstart ? eol : sigstart;
1380-
/* check if message uses CRLF */
1381-
} else if (! (eol = strstr(*sub, "\r\n\r\n"))) {
1381+
} else {
13821382
/* treat whole message as subject */
1383-
eol = strrchr(*sub, '\0');
1383+
eol = sigstart;
13841384
}
13851385
buf = eol;
13861386
*sublen = buf - *sub;

t/t6300-for-each-ref.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,4 +1406,44 @@ test_expect_success 'for-each-ref reports broken tags' '
14061406
refs/tags/broken-tag-*
14071407
'
14081408

1409+
test_expect_success 'set up tag with signature and no blank lines' '
1410+
git tag -F - fake-sig-no-blanks <<-\EOF
1411+
this is the subject
1412+
-----BEGIN PGP SIGNATURE-----
1413+
not a real signature, but we just care about the
1414+
subject/body parsing. It is important here that
1415+
there are no blank lines in the signature.
1416+
-----END PGP SIGNATURE-----
1417+
EOF
1418+
'
1419+
1420+
test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject'
1421+
test_atom refs/tags/fake-sig-no-blanks contents:body ''
1422+
test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig"
1423+
1424+
test_expect_success 'set up tag with CRLF signature' '
1425+
append_cr <<-\EOF |
1426+
this is the subject
1427+
-----BEGIN PGP SIGNATURE-----
1428+
1429+
not a real signature, but we just care about
1430+
the subject/body parsing. It is important here
1431+
that there is a blank line separating this
1432+
from the signature header.
1433+
-----END PGP SIGNATURE-----
1434+
EOF
1435+
git tag -F - --cleanup=verbatim fake-sig-crlf
1436+
'
1437+
1438+
test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject'
1439+
test_atom refs/tags/fake-sig-crlf contents:body ''
1440+
1441+
# CRLF is retained in the signature, so we have to pass our expected value
1442+
# through append_cr. But test_atom requires a shell string, which means command
1443+
# substitution, and the shell will strip trailing newlines from the output of
1444+
# the substitution. Hack around it by adding and then removing a dummy line.
1445+
sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)"
1446+
sig_crlf=${sig_crlf%dummy}
1447+
test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf"
1448+
14091449
test_done

0 commit comments

Comments
 (0)