Bug 1881930 - Be more strict about delimiter after day of week r=arai

Differential Revision: https://phabricator.services.mozilla.com/D207674
This commit is contained in:
Vinny Diehl 2024-04-19 06:06:14 +00:00
parent bcc703fbc9
commit 69bdd20b2c
2 changed files with 10 additions and 7 deletions

View file

@ -1387,13 +1387,14 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
if (IsAsciiDigit(s[index])) {
break;
}
} else {
// Reject numbers directly after letters e.g. foo2
if (IsAsciiDigit(s[index]) && IsAsciiAlpha(s[index - 1])) {
} else if (!strchr(" ,.-/", s[index])) {
// We're only allowing the above delimiters after the day of
// week to prevent things such as "foo_1" from being parsed
// as a date, which may break software which uses this function
// to determine whether or not something is a date.
return false;
}
}
}
int year = -1;
int mday = -1;
@ -3668,8 +3669,8 @@ static bool ToDateString(JSContext* cx, const CallArgs& args, ClippedTime t) {
if (!locale) {
return false;
}
return FormatDate(cx, ForceUTC(cx->realm()), locale,
t.toDouble(), FormatSpec::DateTime, args.rval());
return FormatDate(cx, ForceUTC(cx->realm()), locale, t.toDouble(),
FormatSpec::DateTime, args.rval());
}
static bool DateNoArguments(JSContext* cx, const CallArgs& args) {

View file

@ -63,6 +63,8 @@ const rejected = [
"Sep 26 1995 foo",
"1995 foo Sep 26",
"foo2 Sep 26 1995",
"Tuesday_Sep 26 1995",
"foo_12",
];
for (const format of formats) {