mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1603831 - Fix cookie sorting by date in storage panel r=devtools-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D58074
This commit is contained in:
parent
4572d52ea2
commit
622e16558f
@ -994,7 +994,7 @@ TableWidget.prototype = {
|
||||
|
||||
const sortedItems = this.columns.get(column).sort([...this.items.values()]);
|
||||
for (const [id, col] of this.columns) {
|
||||
if (id != col) {
|
||||
if (id === col) {
|
||||
col.sort(sortedItems);
|
||||
}
|
||||
}
|
||||
@ -1229,8 +1229,6 @@ Column.prototype = {
|
||||
/**
|
||||
* Called when the column is sorted by.
|
||||
*
|
||||
* @param {string} event
|
||||
* The event name of the event. i.e. EVENTS.COLUMN_SORTED
|
||||
* @param {string} column
|
||||
* The id of the column being sorted by.
|
||||
*/
|
||||
|
@ -22,6 +22,11 @@ const endsWithNullRx = /\0$/;
|
||||
const whitespaceRx = /\s+/g;
|
||||
const startsWithZeroRx = /^0/;
|
||||
|
||||
loader.lazyGetter(this, "standardSessionString", () => {
|
||||
const l10n = new Localization(["devtools/client/storage.ftl"], true);
|
||||
return l10n.formatValueSync("storage-expires-session");
|
||||
});
|
||||
|
||||
/**
|
||||
* Sort numbers, strings, IP Addresses, Dates, Filenames, version numbers etc.
|
||||
* "the way humans do."
|
||||
@ -40,6 +45,8 @@ const startsWithZeroRx = /^0/;
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
function naturalSort(a = "", b = "", insensitive = false) {
|
||||
let sessionString = standardSessionString;
|
||||
|
||||
// Ensure we are working with trimmed strings
|
||||
a = (a + "").trim();
|
||||
b = (b + "").trim();
|
||||
@ -47,6 +54,7 @@ function naturalSort(a = "", b = "", insensitive = false) {
|
||||
if (insensitive) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
sessionString = standardSessionString.toLowerCase();
|
||||
}
|
||||
|
||||
// Chunk/tokenize - Here we split the strings into arrays or strings and
|
||||
@ -70,6 +78,19 @@ function naturalSort(a = "", b = "", insensitive = false) {
|
||||
(aHexOrDate && b.match(dateRx) && Date.parse(b)) ||
|
||||
null;
|
||||
|
||||
if (
|
||||
(aHexOrDate || bHexOrDate) &&
|
||||
(a === sessionString || b === sessionString)
|
||||
) {
|
||||
// We have a date and a session string. Move "Session" above the date
|
||||
// (for session cookies)
|
||||
if (a === sessionString) {
|
||||
return -1;
|
||||
} else if (b === sessionString) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Try and sort Hex codes or Dates.
|
||||
if (bHexOrDate) {
|
||||
if (aHexOrDate < bHexOrDate) {
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const l10n = new Localization(["devtools/client/storage.ftl"], true);
|
||||
const sessionString = l10n.formatValueSync("storage-expires-session");
|
||||
const {
|
||||
naturalSortCaseSensitive,
|
||||
naturalSortCaseInsensitive,
|
||||
@ -161,6 +163,44 @@ function run_test() {
|
||||
],
|
||||
"mixed Date types"
|
||||
);
|
||||
runTest(
|
||||
[
|
||||
"Tue, 29 Jun 2021 11:31:17 GMT",
|
||||
"Sun, 14 Jun 2009 11:11:15 GMT",
|
||||
sessionString,
|
||||
"Mon, 15 Jun 2009 20:45:30 GMT",
|
||||
],
|
||||
[
|
||||
sessionString,
|
||||
"Sun, 14 Jun 2009 11:11:15 GMT",
|
||||
"Mon, 15 Jun 2009 20:45:30 GMT",
|
||||
"Tue, 29 Jun 2021 11:31:17 GMT",
|
||||
],
|
||||
`"${sessionString}" amongst date strings`
|
||||
);
|
||||
runTest(
|
||||
[
|
||||
"Madras",
|
||||
"Jalfrezi",
|
||||
"Rogan Josh",
|
||||
"Vindaloo",
|
||||
"Tikka Masala",
|
||||
sessionString,
|
||||
"Masala",
|
||||
"Korma",
|
||||
],
|
||||
[
|
||||
"Jalfrezi",
|
||||
"Korma",
|
||||
"Madras",
|
||||
"Masala",
|
||||
"Rogan Josh",
|
||||
sessionString,
|
||||
"Tikka Masala",
|
||||
"Vindaloo",
|
||||
],
|
||||
`"${sessionString}" amongst strings`
|
||||
);
|
||||
});
|
||||
|
||||
test("version number strings", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user