Skip to content

Commit 7289e7f

Browse files
committed
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
1 parent 21c3970 commit 7289e7f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/binding-mqtt/src/mqtt-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class MqttClient implements ProtocolClient {
6565
const brokerUri: string = `${this.scheme}://` + requestUri.host;
6666
// Keeping the path as the topic for compatibility reasons.
6767
// Current specification allows only form["mqv:filter"]
68-
const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"];
68+
const filter = requestUri.pathname.slice(1) || form["mqv:filter"];
6969

7070
let pool = this.pools.get(brokerUri);
7171

@@ -95,7 +95,7 @@ export default class MqttClient implements ProtocolClient {
9595
const brokerUri: string = `${this.scheme}://` + requestUri.host;
9696
// Keeping the path as the topic for compatibility reasons.
9797
// Current specification allows only form["mqv:filter"]
98-
const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"];
98+
const filter = requestUri.pathname.slice(1) || form["mqv:filter"];
9999

100100
let pool = this.pools.get(brokerUri);
101101

@@ -125,7 +125,7 @@ export default class MqttClient implements ProtocolClient {
125125
public async writeResource(form: MqttForm, content: Content): Promise<void> {
126126
const requestUri = new url.URL(form.href);
127127
const brokerUri = `${this.scheme}://${requestUri.host}`;
128-
const topic = requestUri.pathname.slice(1) ?? form["mqv:topic"];
128+
const topic = requestUri.pathname.slice(1) || form["mqv:topic"];
129129

130130
let pool = this.pools.get(brokerUri);
131131

0 commit comments

Comments
 (0)