From 6e20fbe2999fa402247d9d06423f43e1f231ced5 Mon Sep 17 00:00:00 2001 From: GVRLNKMK <210250673+GVRLNKMK@users.noreply.github.com> Date: Fri, 10 Jul 2026 17:25:18 +0300 Subject: [PATCH] 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. --- classes/CEconItem.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/classes/CEconItem.js b/classes/CEconItem.js index a149563..d432d42 100644 --- a/classes/CEconItem.js +++ b/classes/CEconItem.js @@ -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(); } }