From 467247d09d95b2b0ce1eedba11b03345fc79fb20 Mon Sep 17 00:00:00 2001 From: Alex Godbehere Date: Tue, 14 Jan 2025 11:22:59 +0000 Subject: [PATCH] Fix undefined path check This commit makes the manager check for null and undefined paths. Previously, it only checked `''`, which didn't work because the manager keeps them as undefined by default. --- acs-edge/lib/devices/MQTT.ts | 6 ++---- acs-edge/lib/helpers/typeHandler.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/acs-edge/lib/devices/MQTT.ts b/acs-edge/lib/devices/MQTT.ts index 6e9a2f4c..fd064b52 100644 --- a/acs-edge/lib/devices/MQTT.ts +++ b/acs-edge/lib/devices/MQTT.ts @@ -1,11 +1,9 @@ /* - * Factory+ / AMRC Connectivity Stack (ACS) Edge component - * Copyright 2023 AMRC + * Copyright (c) University of Sheffield AMRC 2025. */ -import {Device, DeviceConnection, deviceOptions} from "../device.js"; +import {DeviceConnection} from "../device.js"; import {log} from "../helpers/log.js"; -import {SparkplugNode} from "../sparkplugNode.js"; import {Metrics, writeValuesToPayload} from "../helpers/typeHandler.js"; import * as mqtt from "mqtt"; import {v4 as uuidv4} from 'uuid'; diff --git a/acs-edge/lib/helpers/typeHandler.ts b/acs-edge/lib/helpers/typeHandler.ts index b22d30ac..279208f5 100644 --- a/acs-edge/lib/helpers/typeHandler.ts +++ b/acs-edge/lib/helpers/typeHandler.ts @@ -1,6 +1,5 @@ /* - * Factory+ / AMRC Connectivity Stack (ACS) Edge component - * Copyright 2023 AMRC + * Copyright (c) University of Sheffield AMRC 2025. */ import {JSONPath} from "jsonpath-plus"; @@ -365,9 +364,11 @@ export function parseValueFromPayload(msg: any, metric: sparkplugMetric, payload .split(delimiter) : msg.toString(); // Handle no path parsing - let newVal = (path != '') ? payload[path] : payload; - - return parseTypeFromString(metric.type, newVal); + if (path == null || path == '') { + return parseTypeFromString(metric.type, payload); + } else { + return parseTypeFromString(metric.type, payload[path]); + } case serialisationType.JSON: try { // Handles error if invalid JSON is sent in if (typeof msg == "string") {