Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit dd17f7b

Browse files
author
Fraser J. Gordon
committed
[[ Bugfix 11261 ]] Over-zealous fix for 11162 broke parsing of internet dates
1 parent 444f464 commit dd17f7b

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

docs/notes/bugfix-11261.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Correct a failure to parse internet dates

engine/src/date.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,11 @@ static bool datetime_parse(const MCDateTimeLocale *p_locale, int4 p_century_cuto
445445
t_valid = true;
446446
break;
447447
}
448-
449-
// FG-2013-09-10 [[ Bug 11162 ]]
450-
// Trailing spaces after an accepted format specifier should be squashed
451-
if (t_valid && !t_skip)
452-
{
453-
while (p_format[1] != '\0' && isspace(p_format[1]))
454-
p_format++;
455-
while (t_input_length > 1 && isspace(t_input[1]))
456-
t_input++, t_input_length--;
457-
}
458448

459449
}
460-
else if (*p_format != *t_input)
450+
// FG-2013-10-08 [[ Bugfix 11261 ]]
451+
// If there is an extra space in the format string, treat it as a match
452+
else if (*p_format != *t_input && !isspace(*p_format))
461453
{
462454
// Unrecognised padding is optional, so advance and skip
463455
if (t_loose_separators)
@@ -486,15 +478,25 @@ static bool datetime_parse(const MCDateTimeLocale *p_locale, int4 p_century_cuto
486478
{
487479
// FG-2013-09-10 [[ Bug 11162 ]]
488480
// One or more spaces in the format string should accept any number of input spaces
489-
while (t_input_length > 0 && isspace(*t_input))
490-
t_input += 1, t_input_length -= 1;
491-
while (*p_format != '\0' && isspace(*p_format))
492-
p_format++;
493-
494-
if (t_input_length > 0)
481+
// FG-2013-10-08 [[ Bug 11261 ]]
482+
// Over-incrementing of format pointer caused internet dates to parse incorrectly
483+
if (isspace(*p_format))
495484
{
496-
t_input += 1;
497-
t_input_length -= 1;
485+
while (t_input_length > 0 && isspace(*t_input))
486+
t_input += 1, t_input_length -= 1;
487+
488+
// Format is incremented past the current char below so just
489+
// remove additional spaces here and leave one for it.
490+
while (p_format[1] != '\0' && isspace(p_format[1]))
491+
p_format++;
492+
}
493+
else
494+
{
495+
if (t_input_length > 0)
496+
{
497+
t_input += 1;
498+
t_input_length -= 1;
499+
}
498500
}
499501
t_valid = true;
500502
}

0 commit comments

Comments
 (0)