Order of day or month and time or year needs to be considered. The year also needs to be adjusted correctly.
-- v3: wininet/internet: Fix year parsing to include millennium.
From: Jacob Czekalla jczekalla@codeweavers.com
--- dlls/wininet/tests/internet.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index f2579c4993a..668b6990840 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -1131,6 +1131,7 @@ static void test_InternetTimeToSystemTime(void) { "Fri Jan 7 12:06:35 2005", &expect1, TRUE, TRUE }, { "Fri Jan 7 12:06:35 2005 GMT", &expect1, TRUE, TRUE }, { "Fri Jan 7 12:06:35 2005 UTC", &expect1, TRUE, TRUE }, + { "Fri, 7-Jan-05 12:06:35 GMT", &expect1, TRUE, TRUE } };
ret = pInternetTimeToSystemTimeA(NULL, NULL, 0);
From: Jacob Czekalla jczekalla@codeweavers.com
Order of day or month and time or year needs to be considered. --- dlls/wininet/internet.c | 128 +++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 40 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 17a7ce9385e..5d7b48a3069 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -3960,6 +3960,70 @@ BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD re return ret; }
+static inline BOOL calc_month(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wMonth = 0; + if (**s == '\0') return TRUE; + + if (iswalpha(**s)) + { + if ((*s)[1] == '\0' || (*s)[2] == '\0') return TRUE; + for (int i = 0; i < 12; i++) + { + if (!wcsnicmp(WININET_month[i], *s, 3)) + { + time->wMonth = i + 1; + *s += 3; + break; + } + } + } + else if (is_time_digit(**s)) + { + time->wMonth = wcstol(*s, &end, 10); + *s = end; + } + return (time->wMonth == 0); +} + +static inline void calc_day(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wDay = wcstol( *s, &end, 10 ); + *s = end; +} + +static inline BOOL calc_time(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + if (**s == '\0') return TRUE; + time->wHour = wcstol( *s, &end, 10 ); + *s = end; + + while (**s && !is_time_digit(**s)) (*s)++; + if (**s == '\0') return TRUE; + time->wMinute = wcstol( *s, &end, 10 ); + *s = end; + + while (**s && !is_time_digit(**s)) (*s)++; + if (**s == '\0') return TRUE; + time->wSecond = wcstol( *s, &end, 10 ); + *s = end; + + time->wMilliseconds = 0; + return FALSE; +} + +static inline BOOL calc_year(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wYear = wcstol( *s, &end, 10 ); + *s = end; + return FALSE; +} + +static inline BOOL is_time(const WCHAR *s) +{ + return (s[1] == L':' || s[2] == L':'); +} + /*********************************************************************** * InternetTimeToSystemTimeW (WININET.@) */ @@ -3992,6 +4056,7 @@ BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD r if (!wcsnicmp(WININET_wkday[i], s, 3)) { time->wDayOfWeek = i; + s += 3; break; } } @@ -4003,54 +4068,37 @@ BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD r } if (time->wDayOfWeek > 6) return TRUE;
- while (*s && !is_time_digit(*s)) s++; - time->wDay = wcstol( s, &end, 10 ); - s = end; - while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; if (*s == '\0') return TRUE; - time->wMonth = 0; - - if (iswalpha(*s)) + if (is_time_digit(*s)) { - if (s[1] == '\0' || s[2] == '\0') return TRUE; - for (i = 0; i < 12; i++) - { - if (!wcsnicmp(WININET_month[i], s, 3)) - { - time->wMonth = i + 1; - break; - } - } - } - else if (is_time_digit(*s)) + calc_day(time, &s, end); + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + if (calc_month(time, &s, end)) + return TRUE; + }else { - time->wMonth = wcstol(s, &end, 10); - s = end; + if (calc_month(time, &s, end)) + return TRUE; + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + calc_day(time, &s, end); } - if (time->wMonth == 0) return TRUE; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wYear = wcstol( s, &end, 10 ); - s = end;
while (*s && !is_time_digit(*s)) s++; if (*s == '\0') return TRUE; - time->wHour = wcstol( s, &end, 10 ); - s = end; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wMinute = wcstol( s, &end, 10 ); - s = end; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wSecond = wcstol( s, &end, 10 ); - s = end; - - time->wMilliseconds = 0; + if (is_time(s)) + { + if (calc_time(time, &s, end)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_year(time, &s, end); + }else + { + if (calc_year(time, &s, end)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_time(time, &s, end); + } return TRUE; }
From: Jacob Czekalla jczekalla@codeweavers.com
Time strings like "25" were parsed as-is instead of "2025". --- dlls/wininet/internet.c | 5 +++++ dlls/wininet/tests/internet.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 5d7b48a3069..94f72af3d6f 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -4014,7 +4014,12 @@ static inline BOOL calc_time(SYSTEMTIME* time, const WCHAR **s, WCHAR *end)
static inline BOOL calc_year(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) { + WORD current_year = time->wYear; + + if (**s == '\0') return TRUE; time->wYear = wcstol( *s, &end, 10 ); + if (1601 > time->wYear) /* year should be between 1601 and 30827 inclusive */ + time->wYear += (current_year - (current_year % 1000)); *s = end; return FALSE; } diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 668b6990840..d9efa415d08 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -1128,10 +1128,10 @@ static void test_InternetTimeToSystemTime(void) { "2, 11*01/2022 11+13=05", &expect2, TRUE }, { "2, 11-Jan-2022 11:13:05", &expect2, TRUE }, { "Fr", NULL, FALSE }, - { "Fri Jan 7 12:06:35 2005", &expect1, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 2005 GMT", &expect1, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 2005 UTC", &expect1, TRUE, TRUE }, - { "Fri, 7-Jan-05 12:06:35 GMT", &expect1, TRUE, TRUE } + { "Fri Jan 7 12:06:35 2005", &expect1, TRUE }, + { "Fri Jan 7 12:06:35 2005 GMT", &expect1, TRUE }, + { "Fri Jan 7 12:06:35 2005 UTC", &expect1, TRUE }, + { "Fri, 7-Jan-05 12:06:35 GMT", &expect1, TRUE } };
ret = pInternetTimeToSystemTimeA(NULL, NULL, 0);
Jacek Caban (@jacek) commented about dlls/wininet/internet.c:
return ret;
}
+static inline BOOL calc_month(SYSTEMTIME* time, const WCHAR **s, WCHAR *end)
The `end` input value is unused, `wcstol` only uses it as an output parameter, so it should probably be a local variable. Also, there’s no need for inline here, similar to the other helpers in this commit.
Jacek Caban (@jacek) commented about dlls/wininet/internet.c:
static inline BOOL calc_year(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) {
- WORD current_year = time->wYear;
- if (**s == '\0') return TRUE; time->wYear = wcstol( *s, &end, 10 );
- if (1601 > time->wYear) /* year should be between 1601 and 30827 inclusive */
It would be nice to have a test case with a less obvious value, such as 100 or 1600.
Jacek Caban (@jacek) commented about dlls/wininet/tests/internet.c:
{ "2, 11*01/2022 11+13=05", &expect2, TRUE }, { "2, 11-Jan-2022 11:13:05", &expect2, TRUE }, { "Fr", NULL, FALSE },
{ "Fri Jan 7 12:06:35 2005", &expect1, TRUE, TRUE },
{ "Fri Jan 7 12:06:35 2005 GMT", &expect1, TRUE, TRUE },
{ "Fri Jan 7 12:06:35 2005 UTC", &expect1, TRUE, TRUE },
Those seem fixed by a previous commit, so tests should be adjusted there.