Order of day or month and time or year needs to be considered. The year also needs to be adjusted correctly.
-- v5: wininet/internet: Fix year parsing to include millennium. wininet/internet: Fix parsing order of http times. wininet/tests: Add more http time test strings.
From: Jacob Czekalla jczekalla@codeweavers.com
--- dlls/wininet/tests/internet.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index f2579c4993a..19023b7940b 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -1105,6 +1105,12 @@ static void test_InternetTimeToSystemTime(void) WCHAR buffer[64]; static const SYSTEMTIME expect1 = { 2005, 1, 5, 7, 12, 6, 35, 0 }; static const SYSTEMTIME expect2 = { 2022, 1, 2, 11, 11, 13, 5, 0 }; + static const SYSTEMTIME expect3 = { 1999, 1, 5, 7, 12, 6, 35, 0 }; + static const SYSTEMTIME expect4 = { 100, 1, 5, 7, 12, 6, 35, 0 }; + static const SYSTEMTIME expect5 = { 1600, 1, 5, 7, 12, 6, 35, 0 }; + static const SYSTEMTIME expect6 = { 30828, 1, 5, 7, 12, 6, 35, 0 }; + static const SYSTEMTIME expect7 = { 2079, 1, 5, 7, 12, 6, 35, 0 }; + static const SYSTEMTIME expect8 = { 1980, 1, 5, 7, 12, 6, 35, 0 };
static const struct test_data { @@ -1131,6 +1137,13 @@ 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 }, + { "Fri Jan 7 12:06:35 99 UTC", &expect3, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 100 UTC", &expect4, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 1600 UTC", &expect5, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 30828 UTC", &expect6, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 79 UTC", &expect7, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 80 UTC", &expect8, 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 | 137 ++++++++++++++++++++++++---------- dlls/wininet/tests/internet.c | 12 +-- 2 files changed, 103 insertions(+), 46 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 17a7ce9385e..c11f9367fb7 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -3960,6 +3960,79 @@ BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD re return ret; }
+static 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 void calc_day(SYSTEMTIME* time, const WCHAR **s) +{ + WCHAR *end; + + time->wDay = wcstol( *s, &end, 10 ); + *s = end; +} + +static 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 BOOL calc_year(SYSTEMTIME* time, const WCHAR **s) +{ + WCHAR *end; + + if (**s == '\0') return TRUE; + time->wYear = wcstol( *s, &end, 10 ); + *s = end; + return FALSE; +} + +static BOOL is_time(const WCHAR *s) +{ + return (s[1] == L':' || s[2] == L':'); +} + /*********************************************************************** * InternetTimeToSystemTimeW (WININET.@) */ @@ -3992,6 +4065,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 +4077,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); + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + if (calc_month(time, &s)) + return TRUE; + }else { - time->wMonth = wcstol(s, &end, 10); - s = end; + if (calc_month(time, &s)) + return TRUE; + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + calc_day(time, &s); } - 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)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_year(time, &s); + }else + { + if (calc_year(time, &s)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_time(time, &s); + } return TRUE; }
diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 19023b7940b..2299e3eba03 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -1134,14 +1134,14 @@ 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 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, TRUE }, { "Fri Jan 7 12:06:35 99 UTC", &expect3, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 100 UTC", &expect4, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 1600 UTC", &expect5, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 30828 UTC", &expect6, TRUE, TRUE }, + { "Fri Jan 7 12:06:35 100 UTC", &expect4, TRUE }, + { "Fri Jan 7 12:06:35 1600 UTC", &expect5, TRUE }, + { "Fri Jan 7 12:06:35 30828 UTC", &expect6, TRUE }, { "Fri Jan 7 12:06:35 79 UTC", &expect7, TRUE, TRUE }, { "Fri Jan 7 12:06:35 80 UTC", &expect8, TRUE, 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 c11f9367fb7..aee0b096cc6 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -4024,6 +4024,11 @@ static BOOL calc_year(SYSTEMTIME* time, const WCHAR **s)
if (**s == '\0') return TRUE; time->wYear = wcstol( *s, &end, 10 ); + if (80 > time->wYear) + time->wYear += 2000; + else if (100 > time->wYear) + time->wYear += 1900; + *s = end; return FALSE; } diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 2299e3eba03..a5325c05cbb 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -1137,13 +1137,13 @@ static void test_InternetTimeToSystemTime(void) { "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, TRUE }, - { "Fri Jan 7 12:06:35 99 UTC", &expect3, TRUE, TRUE }, + { "Fri, 7-Jan-05 12:06:35 GMT", &expect1, TRUE }, + { "Fri Jan 7 12:06:35 99 UTC", &expect3, TRUE }, { "Fri Jan 7 12:06:35 100 UTC", &expect4, TRUE }, { "Fri Jan 7 12:06:35 1600 UTC", &expect5, TRUE }, { "Fri Jan 7 12:06:35 30828 UTC", &expect6, TRUE }, - { "Fri Jan 7 12:06:35 79 UTC", &expect7, TRUE, TRUE }, - { "Fri Jan 7 12:06:35 80 UTC", &expect8, TRUE, TRUE } + { "Fri Jan 7 12:06:35 79 UTC", &expect7, TRUE }, + { "Fri Jan 7 12:06:35 80 UTC", &expect8, TRUE } };
ret = pInternetTimeToSystemTimeA(NULL, NULL, 0);
This merge request was approved by Jacek Caban.