sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit fee20df52a9091ee3a3efeaf3ed63b6940fb5be5
parent 76274ca7980b2f71fc07b2dc59123e3f66b8fd9d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu,  4 Feb 2021 01:19:31 +0100

sfeed.c: fix time parsing regression with non-standard date format

The commit that introduced the regression was:

commit 33c50db302957bca2a850ac8d0b960d05ee0520e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon Oct 12 18:55:35 2020 +0200

    simplify time parsing

Noticed on a RSS feed with the following date:

	<pubDate>2021-02-03 05:13:03</pubDate>

This format is non-standard, but sfeed should support this.
A standard format would be (for Atom): 2021-02-03T05:13:03Z

Partially revert it.

Diffstat:
Msfeed.c | 24+++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -559,10 +559,7 @@ parsetime(const char *s, time_t *tp) isdigit((unsigned char)s[2]) && isdigit((unsigned char)s[3])) { /* formats "%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S" or "%Y%m%d%H%M%S" */ - va[0] = ((s[0] - '0') * 1000) + ((s[1] - '0') * 100) + - ((s[2] - '0') * 10) + (s[3] - '0'); - vi = 1; - s += 4; + vi = 0; } else { /* format: "[%a, ]%d %b %Y %H:%M:%S" */ /* parse "[%a, ]%d %b %Y " part, then use time parsing as above */ @@ -608,16 +605,17 @@ parsetime(const char *s, time_t *tp) } /* parse time parts (and possibly remaining date parts) */ - for (; *s && vi < 6; ) { - if (isdigit((unsigned char)s[0]) && isdigit((unsigned char)s[1])) { - va[vi++] = ((s[0] - '0') * 10) + (s[1] - '0'); - s += 2; - } else if (vi > 2 && (*s == '-' || *s == '+' || *s == '.' || - isspace((unsigned char)*s))) { - break; - } else { - s++; + for (; *s && vi < 6; vi++) { + for (i = 0, v = 0; i < ((vi == 0) ? 4 : 2) && + isdigit((unsigned char)*s); s++, i++) { + v = (v * 10) + (*s - '0'); } + va[vi] = v; + + if ((vi < 2 && *s == '-') || + (vi == 2 && (*s == 'T' || isspace((unsigned char)*s))) || + (vi > 2 && *s == ':')) + s++; } /* skip milliseconds in for example: "%Y-%m-%dT%H:%M:%S.000Z" */