Skip to content

Commit

Permalink
fix(edit): validate MQTT Integration url (#477)
Browse files Browse the repository at this point in the history
Correctly validate MQTT integration Url
  • Loading branch information
mpfeil committed Oct 27, 2023
1 parent b0b7ad0 commit 6bf2b59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/scripts/controllers/account.box.edit.mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
topic: '',
messageFormat: '',
decodeOptions: '',
connectionOptions: ''
connectionOptions: '',
};

vm.save = save;

// Inspired by https://regex101.com/r/mIA28O/1
vm.urlRegEx = /^((mqtt|ws)s?:\/\/)(([^:\s]+):([^:\s]+)@)?([a-zA-Z0-9.-]+)(:\d{1,5})?(\/[^?#\s]*)?$/;
activate();

////
Expand Down
10 changes: 9 additions & 1 deletion app/views/account.box.edit.mqtt.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ <h2 style="margin-top: 0px; margin-bottom: 0px">{{'EDIT_MQTTOPTIONS'|translate}}
<!-- MQTT URL -->
<div ng-class="{'has-error': mqttSettings.mqttURL.$invalid, 'has-success': mqttSettings.mqttURL.$valid }">
<label for="mqttURL">{{ 'MQTT_URL' | translate}}*</label>
<input type="url" name="mqttURL" class="form-control" ng-model="mqtt.settings.url" title="{{ 'PLEASE_SPECIFY_FIRSTNAME' | translate }}" ng-required="mqtt.settings.enabled" ng-disabled="!mqtt.settings.enabled">
<input
type="text"
name="mqttURL"
class="form-control"
ng-model="mqtt.settings.url"
ng-pattern="mqtt.urlRegEx"
title="{{ 'PLEASE_SPECIFY_FIRSTNAME' | translate }}"
ng-required="mqtt.settings.enabled"
ng-disabled="!mqtt.settings.enabled">
</div>

<!-- MQTT TOPIC -->
Expand Down

0 comments on commit 6bf2b59

Please sign in to comment.