From b6a6b9eb27335570189dcefedd2a808b55ed1418 Mon Sep 17 00:00:00 2001 From: jona42-ui Date: Sun, 29 Mar 2026 14:51:52 +0300 Subject: [PATCH] fix(binding-mqtt): replace ?? with || for mqv:filter and mqv:topic fallback The nullish coalescing operator (??) only triggers on null or undefined, not on empty strings. When the URL path is '/', pathname.slice(1) returns '' which is falsy but not null/undefined, causing mqv:filter and mqv:topic to be silently ignored. Fixes #1508 Signed-off-by: jona42-ui --- packages/binding-mqtt/src/mqtt-client.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index 9fc120155..b68a79220 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -65,7 +65,10 @@ export default class MqttClient implements ProtocolClient { const brokerUri: string = `${this.scheme}://` + requestUri.host; // Keeping the path as the topic for compatibility reasons. // Current specification allows only form["mqv:filter"] - const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"]; + const filter = requestUri.pathname.slice(1) || form["mqv:filter"]; + if (filter == null) { + throw new Error("MqttClient: no filter found in form href or mqv:filter"); + } let pool = this.pools.get(brokerUri); @@ -95,7 +98,10 @@ export default class MqttClient implements ProtocolClient { const brokerUri: string = `${this.scheme}://` + requestUri.host; // Keeping the path as the topic for compatibility reasons. // Current specification allows only form["mqv:filter"] - const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"]; + const filter = requestUri.pathname.slice(1) || form["mqv:filter"]; + if (filter == null) { + throw new Error("MqttClient: no filter found in form href or mqv:filter"); + } let pool = this.pools.get(brokerUri); @@ -125,7 +131,10 @@ export default class MqttClient implements ProtocolClient { public async writeResource(form: MqttForm, content: Content): Promise { const requestUri = new url.URL(form.href); const brokerUri = `${this.scheme}://${requestUri.host}`; - const topic = requestUri.pathname.slice(1) ?? form["mqv:topic"]; + const topic = requestUri.pathname.slice(1) || form["mqv:topic"]; + if (topic == null) { + throw new Error("MqttClient: no topic found in form href or mqv:topic"); + } let pool = this.pools.get(brokerUri);