mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Backed out changeset 2516d38fcdfa (bug 1617562) for causing leaks on jsdate.cpp. CLOSED TREE
This commit is contained in:
parent
28fa3a7e8f
commit
0f55032c2b
@ -21,7 +21,6 @@ const startsWithNullRx = /^\0/;
|
||||
const endsWithNullRx = /\0$/;
|
||||
const whitespaceRx = /\s+/g;
|
||||
const startsWithZeroRx = /^0/;
|
||||
const versionRx = /^([\w-]+-)?\d+\.\d+\.\d+$/;
|
||||
|
||||
/**
|
||||
* Sort numbers, strings, IP Addresses, Dates, Filenames, version numbers etc.
|
||||
@ -66,9 +65,9 @@ function naturalSort(a = "", b = "", sessionString, insensitive = false) {
|
||||
|
||||
// Hex or date detection.
|
||||
const aHexOrDate =
|
||||
parseInt(a.match(hexRx), 16) || (!versionRx.test(a) && Date.parse(a));
|
||||
parseInt(a.match(hexRx), 16) || (aChunks.length > 3 && Date.parse(a));
|
||||
const bHexOrDate =
|
||||
parseInt(b.match(hexRx), 16) || (!versionRx.test(b) && Date.parse(b));
|
||||
parseInt(b.match(hexRx), 16) || (bChunks.length > 3 && Date.parse(b));
|
||||
|
||||
if (
|
||||
(aHexOrDate || bHexOrDate) &&
|
||||
|
@ -281,48 +281,6 @@ function run_test() {
|
||||
],
|
||||
"string first"
|
||||
);
|
||||
runTest(
|
||||
[
|
||||
"1.1.3",
|
||||
"a-release-1.1.3",
|
||||
"b-release-1.1.3",
|
||||
"1.2.3",
|
||||
"a-release-1.2.3",
|
||||
"b-release-1.2.3",
|
||||
"1.1.4",
|
||||
"a-release-1.1.4",
|
||||
"b-release-1.1.4",
|
||||
"1.1.1",
|
||||
"a-release-1.1.1",
|
||||
"b-release-1.1.1",
|
||||
"1.0.5",
|
||||
"a-release-1.0.5",
|
||||
"b-release-1.0.5",
|
||||
],
|
||||
[
|
||||
"1.0.5",
|
||||
"1.1.1",
|
||||
"1.1.3",
|
||||
"1.1.4",
|
||||
"1.2.3",
|
||||
"a-release-1.0.5",
|
||||
"a-release-1.1.1",
|
||||
"a-release-1.1.3",
|
||||
"a-release-1.1.4",
|
||||
"a-release-1.2.3",
|
||||
"b-release-1.0.5",
|
||||
"b-release-1.1.1",
|
||||
"b-release-1.1.3",
|
||||
"b-release-1.1.4",
|
||||
"b-release-1.2.3",
|
||||
],
|
||||
"string first, different names"
|
||||
);
|
||||
runTest(
|
||||
["zstring", "astring", "release-1.1.3"],
|
||||
["astring", "release-1.1.3", "zstring"],
|
||||
"string first, mixed with regular strings"
|
||||
);
|
||||
});
|
||||
|
||||
test("numerics", function () {
|
||||
|
@ -1139,8 +1139,6 @@ static constexpr const char* const months_names[] = {
|
||||
"january", "february", "march", "april", "may", "june",
|
||||
"july", "august", "september", "october", "november", "december",
|
||||
};
|
||||
// The shortest month is "may".
|
||||
static constexpr size_t ShortestMonthNameLength = 3;
|
||||
|
||||
/*
|
||||
* Try to parse the following date formats:
|
||||
@ -1156,14 +1154,13 @@ template <typename CharT>
|
||||
static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
|
||||
size_t* indexOut, int* yearOut,
|
||||
int* monOut, int* mdayOut) {
|
||||
size_t i = *indexOut;
|
||||
size_t i = 0;
|
||||
|
||||
size_t pre = i;
|
||||
size_t mday;
|
||||
if (!ParseDigitsNOrLess(6, &mday, s, &i, length)) {
|
||||
return false;
|
||||
}
|
||||
size_t mdayDigits = i - pre;
|
||||
size_t mdayDigits = i;
|
||||
|
||||
if (i >= length || s[i] != '-') {
|
||||
return false;
|
||||
@ -1177,6 +1174,8 @@ static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
|
||||
}
|
||||
}
|
||||
|
||||
// The shortest month is "may".
|
||||
static constexpr size_t ShortestMonthNameLength = 3;
|
||||
if (i - start < ShortestMonthNameLength) {
|
||||
return false;
|
||||
}
|
||||
@ -1200,7 +1199,7 @@ static bool TryParseDashedDatePrefix(const CharT* s, size_t length,
|
||||
}
|
||||
++i;
|
||||
|
||||
pre = i;
|
||||
size_t pre = i;
|
||||
size_t year;
|
||||
if (!ParseDigitsNOrLess(6, &year, s, &i, length)) {
|
||||
return false;
|
||||
@ -1250,7 +1249,7 @@ template <typename CharT>
|
||||
static bool TryParseDashedNumericDatePrefix(const CharT* s, size_t length,
|
||||
size_t* indexOut, int* yearOut,
|
||||
int* monOut, int* mdayOut) {
|
||||
size_t i = *indexOut;
|
||||
size_t i = 0;
|
||||
|
||||
size_t first;
|
||||
if (!ParseDigitsNOrLess(6, &first, s, &i, length)) {
|
||||
@ -1381,61 +1380,16 @@ constexpr size_t MinKeywordLength(const CharsAndAction (&keywords)[N]) {
|
||||
template <typename CharT>
|
||||
static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
|
||||
size_t length, ClippedTime* result) {
|
||||
if (length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ParseISOStyleDate(forceUTC, s, length, result)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
int mon = -1;
|
||||
bool seenMonthName = false;
|
||||
|
||||
// Before we begin, we need to scrub any words from the beginning of the
|
||||
// string that are not a month name
|
||||
for (; index < length; ++index) {
|
||||
int c = s[index];
|
||||
|
||||
if (strchr(" ,.-/", c)) {
|
||||
continue;
|
||||
}
|
||||
if (!IsAsciiAlpha(c)) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t start = index;
|
||||
while (index < length) {
|
||||
++index;
|
||||
if (!IsAsciiAlpha(s[index])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index - start < ShortestMonthNameLength) {
|
||||
// If it's too short, it's definitely not a month name, ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t m = 0; m < std::size(months_names); ++m) {
|
||||
// If the field isn't a prefix of the month (an exact match is *not*
|
||||
// required), try the next one.
|
||||
if (IsPrefixOfKeyword(s + start, index - start, months_names[m])) {
|
||||
// Use numeric value.
|
||||
mon = m + 1;
|
||||
seenMonthName = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (seenMonthName) {
|
||||
// If we've found the month name, we're done with this loop, otherwise we
|
||||
// move on to the next word
|
||||
break;
|
||||
}
|
||||
if (length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int year = -1;
|
||||
int mon = -1;
|
||||
int mday = -1;
|
||||
int hour = -1;
|
||||
int min = -1;
|
||||
@ -1447,11 +1401,14 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
|
||||
int prevc = 0;
|
||||
|
||||
bool seenPlusMinus = false;
|
||||
bool seenMonthName = false;
|
||||
bool seenFullYear = false;
|
||||
bool negativeYear = false;
|
||||
// Includes "GMT", "UTC", "UT", and "Z" timezone keywords
|
||||
bool seenGmtAbbr = false;
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
// Try parsing the leading dashed-date.
|
||||
//
|
||||
// If successfully parsed, index is updated to the end of the date part,
|
||||
@ -1729,9 +1686,7 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
|
||||
// date component and set the month here.
|
||||
if (action <= 12) {
|
||||
if (seenMonthName) {
|
||||
// Overwrite the previous month name
|
||||
mon = action;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
seenMonthName = true;
|
||||
@ -1766,7 +1721,7 @@ static bool ParseDate(DateTimeInfo::ForceUTC forceUTC, const CharT* s,
|
||||
break;
|
||||
}
|
||||
|
||||
if (k == size_t(-1) && (!seenMonthName || mday != -1)) {
|
||||
if (k == size_t(-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,92 +0,0 @@
|
||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const expectedDate = new Date("1995-09-26T00:00:00");
|
||||
|
||||
// Each prefix will be tested with each format:
|
||||
const prefixes = [
|
||||
"Tuesday, ",
|
||||
"Tuesday ",
|
||||
"Tuesday,",
|
||||
"Tuesday.",
|
||||
"Tuesday-",
|
||||
"Tuesday/",
|
||||
|
||||
// Case insensitive
|
||||
"tuesday, ",
|
||||
"tUeSdAy ",
|
||||
|
||||
// Abbreviations are valid down to the first character
|
||||
"Tuesda ",
|
||||
"Tue ",
|
||||
"T ",
|
||||
"t,",
|
||||
|
||||
// Floating delimiters at beginning are allowed/ignored
|
||||
" ",
|
||||
",",
|
||||
", ",
|
||||
".",
|
||||
"-",
|
||||
"/",
|
||||
|
||||
// It doesn't actually need to be the correct day of the week, or
|
||||
// a day of week at all...you can put anything there
|
||||
"Monday ",
|
||||
"foo bar "
|
||||
];
|
||||
const formats = [
|
||||
"Sep 26 1995",
|
||||
"26 Sep 1995",
|
||||
"September 26, 1995",
|
||||
"26-Sep-1995",
|
||||
"1995-9-26",
|
||||
// ISO format is non-formal with day of week in front
|
||||
"1995-09-26",
|
||||
|
||||
// You can put anything between the month and mday
|
||||
"Sep foo bar 26 1995",
|
||||
"Sep-foo bar-26 1995",
|
||||
"Sep-foo-bar-26 1995",
|
||||
|
||||
// Redundant month names are allowed
|
||||
"Sep sep 26 1995",
|
||||
"Sep 26 sep 1995",
|
||||
// Edge case: if multiple month names, use the last one
|
||||
"Jan 26 1995 sep",
|
||||
];
|
||||
|
||||
const rejected = [
|
||||
"Sep 26 foo 1995",
|
||||
"Sep 26 1995 foo",
|
||||
"1995 foo Sep 26",
|
||||
];
|
||||
|
||||
for (const format of formats) {
|
||||
for (const prefix of prefixes) {
|
||||
const test = prefix + format;
|
||||
const testDate = new Date(test);
|
||||
|
||||
assertEq(
|
||||
false, isNaN(testDate),
|
||||
`${test} should be accepted.`
|
||||
);
|
||||
|
||||
assertEq(
|
||||
testDate.getTime(), expectedDate.getTime(),
|
||||
`"${test}" should be ${expectedDate} (got ${testDate}).`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const reject of rejected) {
|
||||
assertEq(
|
||||
true, isNaN(new Date(reject)),
|
||||
`"${reject}" should be rejected.`
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
Loading…
Reference in New Issue
Block a user