Validate MQTT In topics

Fixes #792
This commit is contained in:
Nick O'Leary 2016-02-10 22:38:59 +00:00
parent 4fe7ea00b0
commit 3a97e20bde
2 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,5 @@
<!--
Copyright 2013,2015 IBM Corp.
Copyright 2013, 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@ -37,7 +37,7 @@
category: 'input',
defaults: {
name: {value:""},
topic: {value:"",required:true},
topic: {value:"",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)},
broker: {type:"mqtt-broker", required:true}
},
color:"#d8bfd8",

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013,2015 IBM Corp.
* Copyright 2013, 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -306,6 +306,9 @@ module.exports = function(RED) {
this.topic = n.topic;
this.broker = n.broker;
this.brokerConn = RED.nodes.getNode(this.broker);
if (!/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/.test(this.topic)) {
return this.warn(RED._("mqtt.errors.invalid-topic"));
}
var node = this;
if (this.brokerConn) {
this.status({fill:"red",shape:"ring",text:"common.status.disconnected"});