Fix CEconItem crash when Tradable/Marketable After date isn't day-first

CEconItem destructured the day-first date regex match without a null
check, throwing 'match is not iterable' for CS2 items whose
owner_descriptions use the legacy month-first format (e.g. 'Tradable/
Marketable After Jul 11, 2025 (2:00:00)'). Running in the constructor,
this made getInventoryContents()/getUserInventoryContents() reject the
whole inventory.

Guard the null match, fall back to parsing the legacy month-first
format, and only set cache_expiration for a valid date. Day-first
strings are unchanged; backwards-compatible.
This commit is contained in:
GVRLNKMK
2026-07-10 17:25:18 +03:00
parent 00e82f7e79
commit 6e20fbe299

View File

@@ -70,19 +70,24 @@ function CEconItem(item, description, contextID, assetProperties) {
if (this.appid == 730 && this.contextid == 2 && this.owner_descriptions) {
let description = this.owner_descriptions.find((d) => d.value && d.value.indexOf("Tradable/Marketable After ") == 0);
if (description) {
let date;
const match = description.value.match(/(\d{1,2}) (\w+) @ (\d{1,2}:\d{2})(am|pm)/i);
const [, day, month, time, meridian] = match;
const now = new Date();
let year = now.getFullYear();
let date = new Date(`${day} ${month} ${year} ${time} ${meridian}`);
if (match) {
// New day-first format, e.g. "Tradable/Marketable After 17 Jul @ 3:00am"
const [, day, month, time, meridian] = match;
const now = new Date();
let year = now.getFullYear();
date = new Date(`${day} ${month} ${year} ${time} ${meridian}`);
if (date.getTime() < now.getTime()) {
date = new Date(
`${day} ${month} ${year + 1} ${time} ${meridian}`,
);
if (date.getTime() < now.getTime()) {
date = new Date(`${day} ${month} ${year + 1} ${time} ${meridian}`);
}
} else {
// Legacy month-first format, e.g. "Tradable/Marketable After Jul 11, 2025 (2:00:00)"
date = new Date(description.value.substring("Tradable/Marketable After ".length).replace(/[,()]/g, ""));
}
if (date) {
if (date && !isNaN(date.getTime())) {
this.cache_expiration = date.toISOString();
}
}