From 17abfa51ca4a34d6320d8d605ad4002990fd2f10 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Wed, 26 Aug 2020 10:23:00 -0700 Subject: [PATCH] libc: tmparse should ignore leading whitespace We almost always want to skip leading whitespace in time formats, so make tmparse just do it. This fixes upas mbox parsing, which leaves a leading whitespace at the start of the date. --- sys/man/2/tmdate | 1 + sys/src/libc/port/date.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/man/2/tmdate b/sys/man/2/tmdate index 96e410c14..98c70eb8b 100644 --- a/sys/man/2/tmdate +++ b/sys/man/2/tmdate @@ -65,6 +65,7 @@ Tmstime is identical to tmtime, but accepts the time in sec- onds. .PP Tmparse parses a time from a string according to the format argument. +Leading whitespace is ignored. The point at which the parsing stopped is returned in .IR ep . If diff --git a/sys/src/libc/port/date.c b/sys/src/libc/port/date.c index 0e9669eeb..7ca93856b 100644 --- a/sys/src/libc/port/date.c +++ b/sys/src/libc/port/date.c @@ -632,6 +632,20 @@ tmparse(Tm *tm, char *fmt, char *str, Tzone *tz, char **ep) sloppy = 1; p++; } + + /* Skip whitespace */ + for(;; p++) { + switch(*p) { + case ' ': + case '\t': + case '\n': + case '\f': + case '\r': + case '\v': + continue; + } + break; + } while(*p){ w = 1; c0 = *p++; @@ -868,7 +882,6 @@ Zoneparsed: case '_': case ',': case ' ': - if(*s != ' ' && *s != '\t' && *s != ',' && *s != '\n' && *s != '\0') goto baddate; p += strspn(p, " ,_\t\n"); @@ -884,6 +897,7 @@ Zoneparsed: if(!ok) goto baddate; } + if(*p != '\0') goto baddate; if(ep != nil)