Skip to content

Commit ebaaa00

Browse files
committed
fix whitespace
1 parent 74b2328 commit ebaaa00

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

git-object/src/parsed/tag.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bstr::{BStr, ByteSlice};
77
use btoi::btoi;
88
use hex::FromHex;
99
use nom::bytes::complete::{is_not, take_till};
10+
use nom::combinator::{all_consuming, recognize};
1011
use nom::sequence::delimited;
1112
use nom::{
1213
branch::alt,
@@ -167,7 +168,7 @@ pub(crate) fn parse_tag_nom(i: &[u8]) -> IResult<&[u8], Tag, Error> {
167168

168169
let (i, signature) = terminated(preceded(tag(b"tagger "), parse_signature_nom), tag(NL))(i)
169170
.map_err(Error::context("tagger <signature>"))?;
170-
let (i, (message, pgp_signature)) = parse_message_nom(i)?;
171+
let (i, (message, pgp_signature)) = all_consuming(parse_message_nom)(i)?;
171172
Ok((
172173
i,
173174
Tag {
@@ -182,9 +183,8 @@ pub(crate) fn parse_tag_nom(i: &[u8]) -> IResult<&[u8], Tag, Error> {
182183
}
183184

184185
pub(crate) fn parse_message_nom(i: &[u8]) -> IResult<&[u8], (&BStr, Option<&BStr>), Error> {
185-
let NLNL: &[u8] = b"\n\n";
186-
const PGP_SIGNATURE_BEGIN: &[u8] = b"-----BEGIN PGP SIGNATURE-----";
187-
const PGP_SIGNATURE_END: &[u8] = b"-----END PGP SIGNATURE-----";
186+
const PGP_SIGNATURE_BEGIN: &[u8] = b"\n-----BEGIN PGP SIGNATURE-----";
187+
const PGP_SIGNATURE_END: &[u8] = b"-----END PGP SIGNATURE-----\n";
188188

189189
let (i, _) = tag(NL)(i)?;
190190
if i.is_empty() {
@@ -197,16 +197,23 @@ pub(crate) fn parse_message_nom(i: &[u8]) -> IResult<&[u8], (&BStr, Option<&BStr
197197
"tag message is missing",
198198
)));
199199
}
200-
tag(NL)(&i[i.len() - 1..]).map_err(Error::context("tag message must end with newline"))?;
201-
Ok((&[], (&i[..i.len() - 1], &[])))
200+
let (i, _) = tag(NL)(&i[i.len() - 1..])
201+
.map_err(Error::context("tag message must end with newline"))?;
202+
// an empty signature message signals that there is none - the function signature is needed
203+
// to work with 'alt(…)'. PGP signatures are never empty
204+
Ok((i, (&i[..i.len() - 1], &[])))
202205
}
203206
let (i, (message, signature)) = alt((
204207
tuple((
205208
take_until(PGP_SIGNATURE_BEGIN),
206209
delimited(
207-
tag(PGP_SIGNATURE_BEGIN),
208-
take_until(PGP_SIGNATURE_END),
209-
tag(PGP_SIGNATURE_END),
210+
tag(NL),
211+
recognize(delimited(
212+
tag(&PGP_SIGNATURE_BEGIN[1..]),
213+
take_until(PGP_SIGNATURE_END),
214+
tag(&PGP_SIGNATURE_END[..PGP_SIGNATURE_END.len() - 1]),
215+
)),
216+
tag(NL),
210217
),
211218
)),
212219
all_but_trailing_newline,

git-object/src/parsed/tests/tag.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn tag_fixture(offset: i32) -> parsed::Tag<'static> {
3434
target: b"ffa700b4aca13b80cb6b98a078e7c96804f8e0ec".as_bstr(),
3535
name: b"1.0.0".as_bstr(),
3636
target_kind: Kind::Commit,
37-
message: b"for the signature\n".as_bstr(),
37+
message: b"for the signature".as_bstr(),
3838
pgp_signature: Some(
3939
b"-----BEGIN PGP SIGNATURE-----
4040
Comment: GPGTools - https://gpgtools.org
@@ -52,9 +52,8 @@ Z5fFXEUCO8d5WT56jzKDjmVoY01lA87O1YsP/J+zQAlc9v1k6jqeQ53LZNgTN+ue
5252
cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
5353
2n8f2douw6624Tn/6Lm4a7AoxmU+CMiYagDxDL3RuZ8CAfh3bn0=
5454
=aIns
55-
-----END PGP SIGNATURE-----
56-
"
57-
.as_bstr(),
55+
-----END PGP SIGNATURE-----"
56+
.as_bstr(),
5857
),
5958
signature: parsed::Signature {
6059
name: b"Sebastian Thiel".as_bstr(),

0 commit comments

Comments
 (0)