diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-11-27 12:27:37 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-11-27 12:27:37 +0200 |
commit | df29254df82d4aa466f066dd76e00446e540e1cb (patch) | |
tree | 344d437a084650c7ce414c4e67df99d1f7292904 /libmailutils/tests | |
parent | d13ccd98c79b9f5dc658c1dd5b1cb2287377affb (diff) | |
download | mailutils-df29254df82d4aa466f066dd76e00446e540e1cb.tar.gz mailutils-df29254df82d4aa466f066dd76e00446e540e1cb.tar.bz2 |
mu_scan_datetime: Fix error recovery. %Z handles both time-zone forms.
The value stored in the memory location pointed to by the endp argument
has changed. On the MU_ERR_PARSE error, it is (as earlier) the position
in input where conversion stopped. On the MU_ERR_FORMAT, however, it
is the character in fmt where the format error was detected.
* libmailutils/datetime/scantime.c (peek_state): Return MU_ERR_FORMAT
if mu_list_tail fails (the list is empty). This reflects unbalanced
closing parenthesis or bracket.
(scan_recovery): fix algorithm.
(mu_scan_datetime): %Z handles both abbreviated time-zones and
time-zones as hour offset from GMT.
Improve error handling.
On MU_ERR_PARSE error, point *endp to the character in input where
conversion stopped.
On MU_ERR_FORMAT error, point it to the character in fmt, where the
format error was detected.
* libmailutils/tests/scantime.c: Improve error handling.
* libmailutils/tests/scantime.at: More testcases.
Diffstat (limited to 'libmailutils/tests')
-rw-r--r-- | libmailutils/tests/scantime.at | 84 | ||||
-rw-r--r-- | libmailutils/tests/scantime.c | 14 |
2 files changed, 97 insertions, 1 deletions
diff --git a/libmailutils/tests/scantime.at b/libmailutils/tests/scantime.at index 3b5a1b1a1..7969158f4 100644 --- a/libmailutils/tests/scantime.at +++ b/libmailutils/tests/scantime.at @@ -153,5 +153,89 @@ sec=26,min=25,hour=13,mday=3,mon=4,year=111,wday=2,yday=122,tz=7200 scantime: 5: parse failed near ; 03 May 2011 13:25:26 +0200 ]) +# This expanded scan specification takes into account all possible +# variants of the date/time specification that ever existed in the +# From_ line of UNIX mbox mailboxes. +SCANTIME([MBOX From_ time],[from_], +[[%a %b %e %H:%M%[:%S%] %(%(%z%|%Z%) %Y%|%Y %(%z%|%Z%)%|%Y%)]], +[Wed Dec 2 05:53 1992 +Wed Dec 2 05:53:22 1992 +Wed Dec 2 05:53 PST 1992 +Wed Dec 2 05:53:22 PST 1992 +Wed Dec 2 05:53 -0700 1992 +Wed Dec 2 05:53:22 -0700 1992 +Wed Dec 2 05:53 1992 PST +Wed Dec 2 05:53:22 1992 PST +Wed Dec 2 05:53 1992 -0700 +Wed Dec 2 05:53:22 1992 -0700 +], +[sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +]) + +# This one is a simplification of the above, taking into account the +# fact that %Z handles correctly numeric time zones as well (after +# 2020-11-27). Notice ordering of the alternative forms. +SCANTIME([MBOX From_ time (alternative)],[from_], +[[%a %b %e %H:%M%[:%S%] %(%(%Z %Y%|%Y %Z%)%|%Y%)]], +[Wed Dec 2 05:53 1992 +Wed Dec 2 05:53:22 1992 +Wed Dec 2 05:53 PST 1992 +Wed Dec 2 05:53:22 PST 1992 +Wed Dec 2 05:53 -0700 1992 +Wed Dec 2 05:53:22 -0700 1992 +Wed Dec 2 05:53 1992 PST +Wed Dec 2 05:53:22 1992 PST +Wed Dec 2 05:53 1992 -0700 +Wed Dec 2 05:53:22 1992 -0700 +], +[sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +]) + +# This is a final version of the From_ format line. It eliminates +# one level of alternative specs by joining "%Y %Z" and "%Y" into +# one spec. +SCANTIME([MBOX From_ time (simplified)],[from_], +[[%a %b %e %H:%M%[:%S%] %(%Z %Y%|%Y%[ %Z%]%)]], +[Wed Dec 2 05:53 1992 +Wed Dec 2 05:53:22 1992 +Wed Dec 2 05:53 PST 1992 +Wed Dec 2 05:53:22 PST 1992 +Wed Dec 2 05:53 -0700 1992 +Wed Dec 2 05:53:22 -0700 1992 +Wed Dec 2 05:53 1992 PST +Wed Dec 2 05:53:22 1992 PST +Wed Dec 2 05:53 1992 -0700 +Wed Dec 2 05:53:22 1992 -0700 +], +[sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=0 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-28800 +sec=0,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +sec=22,min=53,hour=5,mday=2,mon=11,year=92,wday=3,yday=336,tz=-25200 +]) + m4_popdef([SCANTIME]) dnl --------------------------------------------------------------------- diff --git a/libmailutils/tests/scantime.c b/libmailutils/tests/scantime.c index a9a01af71..5a0d51141 100644 --- a/libmailutils/tests/scantime.c +++ b/libmailutils/tests/scantime.c @@ -65,13 +65,25 @@ main (int argc, char **argv) if (!*buf) continue; rc = mu_scan_datetime (buf, format, &tm, &tz, &endp); - if (rc) + switch (rc) { + case 0: + break; + + case MU_ERR_PARSE: if (*endp) mu_error ("%d: parse failed near %s", line, endp); else mu_error ("%d: parse failed at end of input", line); continue; + + case MU_ERR_FORMAT: + mu_error ("%d: error in format string near %s", line, endp); + continue; + + default: + mu_error ("%d: %s", line, mu_strerror (rc)); + exit (1); } if (*endp) mu_printf ("# %d: stopped at %s\n", line, endp); |