@@ -6,7 +6,7 @@ pub(crate) mod function {
66 use winnow:: error:: { ErrMode , ErrorKind } ;
77 use winnow:: stream:: Stream ;
88 use winnow:: {
9- combinator:: { alt, separated_pair, terminated} ,
9+ combinator:: { alt, opt , separated_pair, terminated} ,
1010 error:: { AddContext , ParserError , StrContext } ,
1111 prelude:: * ,
1212 stream:: AsChar ,
@@ -21,8 +21,8 @@ pub(crate) mod function {
2121 ) -> PResult < SignatureRef < ' a > , E > {
2222 separated_pair (
2323 identity,
24- b" " ,
25- (
24+ opt ( b" " ) ,
25+ opt ( (
2626 terminated ( take_until ( 0 .., SPACE ) , take ( 1usize ) )
2727 . verify_map ( |v| to_signed :: < SecondsSinceUnixEpoch > ( v) . ok ( ) )
2828 . context ( StrContext :: Expected ( "<timestamp>" . into ( ) ) ) ,
@@ -38,8 +38,9 @@ pub(crate) mod function {
3838 . verify_map ( |v| to_signed :: < OffsetInSeconds > ( v) . ok ( ) )
3939 . context ( StrContext :: Expected ( "MM" . into ( ) ) ) ,
4040 take_while ( 0 .., AsChar :: is_dec_digit) . map ( |v : & [ u8 ] | v) ,
41- )
42- . map ( |( time, sign, hours, minutes, trailing_digits) | {
41+ ) )
42+ . map ( |maybe_timestamp| {
43+ if let Some ( ( time, sign, hours, minutes, trailing_digits) ) = maybe_timestamp {
4344 let offset = if trailing_digits. is_empty ( ) {
4445 ( hours * 3600 + minutes * 60 ) * if sign == Sign :: Minus { -1 } else { 1 }
4546 } else {
@@ -50,7 +51,10 @@ pub(crate) mod function {
5051 offset,
5152 sign,
5253 }
53- } ) ,
54+ } else {
55+ Time :: new ( 0 , 0 )
56+ }
57+ } ) ,
5458 )
5559 . context ( StrContext :: Expected ( "<name> <<email>> <timestamp> <+|-><HHMM>" . into ( ) ) )
5660 . map ( |( identity, time) | SignatureRef {
@@ -206,12 +210,9 @@ mod tests {
206210 #[ test]
207211 fn invalid_time ( ) {
208212 assert_eq ! (
209- decode. parse_peek( b"hello <> abc -1215" )
210- . map_err( to_bstr_err)
211- . expect_err( "parse fails as > is missing" )
212- . to_string( ) ,
213- "in predicate verification at 'abc -1215'\n 0: expected `<timestamp>` at 'abc -1215'\n 1: expected `<name> <<email>> <timestamp> <+|-><HHMM>` at 'hello <> abc -1215'\n "
214- ) ;
213+ decode. parse_peek( b"hello <> abc -1215" ) . expect( "parse to work" ) . 1 ,
214+ signature( "hello" , "" , 0 , Sign :: Plus , 0 )
215+ ) ;
215216 }
216217 }
217218}
0 commit comments