diff --git a/lib/src/binding_mqtt/mqtt_extensions.dart b/lib/src/binding_mqtt/mqtt_extensions.dart index 8be43d33..5d71be99 100644 --- a/lib/src/binding_mqtt/mqtt_extensions.dart +++ b/lib/src/binding_mqtt/mqtt_extensions.dart @@ -62,6 +62,16 @@ extension MqttUriExtension on Uri { throw StateError('MQTT URI scheme $scheme is not supported.'); } + + String get _mqttTopic { + final path = Uri.decodeComponent(this.path); + + if (path.isEmpty) { + return path; + } + + return path.substring(1); + } } /// Additional methods for making MQTT [Form]s easier to work with. @@ -99,20 +109,13 @@ extension MqttFormExtension on Form { return topic; } - final path = Uri.decodeComponent(href.path); - - if (path.isEmpty) { - return path; - } - - return path.substring(1); + return href._mqttTopic; } /// Gets the MQTT topic for subscribing from this [Form]. /// /// If present, this getter uses the dedicated vocabulary term `filter`. - /// Otherwise, the URI query from the `href` field is being used as a - /// fallback. + /// Otherwise, the URI path from the `href` field is being used as a fallback. String get topicFilter { final topic = _obtainVocabularyTerm('filter'); @@ -120,7 +123,7 @@ extension MqttFormExtension on Form { return topic; } - return Uri.decodeComponent(href.query.replaceAll('&', '/')); + return href._mqttTopic; } /// Gets the MQTT `retain` value from this [Form] if present.