diff --git a/public/packet-helpers.js b/public/packet-helpers.js index 5a97a573..3c20b382 100644 --- a/public/packet-helpers.js +++ b/public/packet-helpers.js @@ -10,7 +10,7 @@ */ window.getParsedPath = function getParsedPath(p) { - if (p._parsedPath !== undefined) return p._parsedPath; + if (p._parsedPath !== undefined) return p._parsedPath || []; var raw = p.path_json; if (typeof raw !== 'string') { p._parsedPath = Array.isArray(raw) ? raw : []; @@ -32,7 +32,7 @@ window.clearParsedCache = function clearParsedCache(p) { }; window.getParsedDecoded = function getParsedDecoded(p) { - if (p._parsedDecoded !== undefined) return p._parsedDecoded; + if (p._parsedDecoded !== undefined) return p._parsedDecoded || {}; var raw = p.decoded_json; if (typeof raw !== 'string') { p._parsedDecoded = (raw && typeof raw === 'object') ? raw : {}; diff --git a/public/packets.js b/public/packets.js index e42bf384..12432e2c 100644 --- a/public/packets.js +++ b/public/packets.js @@ -1100,8 +1100,8 @@ // Build HTML for a single flat (ungrouped) packet row function buildFlatRowHtml(p) { - const decoded = getParsedDecoded(p); - const pathHops = getParsedPath(p); + const decoded = getParsedDecoded(p) || {}; + const pathHops = getParsedPath(p) || []; const region = p.observer_id ? (observerMap.get(p.observer_id)?.iata || '') : ''; const typeName = payloadTypeName(p.payload_type); const typeClass = payloadTypeColor(p.payload_type); @@ -1441,8 +1441,8 @@ const pkt = data.packet; const breakdown = data.breakdown || {}; const ranges = breakdown.ranges || []; - const decoded = getParsedDecoded(pkt); - const pathHops = getParsedPath(pkt); + const decoded = getParsedDecoded(pkt) || {}; + const pathHops = getParsedPath(pkt) || []; // Resolve sender GPS — from packet directly, or from known node in DB let senderLat = decoded.lat != null ? decoded.lat : (decoded.latitude || null); diff --git a/test-frontend-helpers.js b/test-frontend-helpers.js index b0ba546e..b36de08d 100644 --- a/test-frontend-helpers.js +++ b/test-frontend-helpers.js @@ -4183,7 +4183,17 @@ console.log('\n=== app.js: routeTypeName/payloadTypeName edge cases ==='); assertJsonEqual(getParsedPath(p), []); }); + test('getParsedPath: cached null _parsedPath returns empty array (#538)', () => { + const p = { path_json: '["a"]', _parsedPath: null }; + assertJsonEqual(getParsedPath(p), []); + }); + // --- getParsedDecoded --- + test('getParsedDecoded: cached null _parsedDecoded returns empty object (#538)', () => { + const p = { decoded_json: '{"x":1}', _parsedDecoded: null }; + assertJsonEqual(getParsedDecoded(p), {}); + }); + test('getParsedDecoded: valid JSON object', () => { const p = { decoded_json: '{"type":"GRP_TXT","text":"hello"}' }; const result = getParsedDecoded(p);