1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Make bad word filter only operate on strings - drop anything else.

This commit is contained in:
Dave C-J 2013-11-09 17:12:19 +00:00
parent 28e82c1351
commit 6425bd75cb
2 changed files with 6 additions and 5 deletions

View File

@ -22,7 +22,8 @@
</script>
<script type="text/x-red" data-help-name="badwords">
<p>Analyses the <b>msg.payload</b> and tries to filter out any messages containing bad swear words...</p>
<p>Analyses the <b>msg.payload</b> and tries to filter out any messages containing bad swear words...</p>
<p><b>Note:</b> this only operates on payloads of type <b>string</b>. Everything else is blocked.</p>
</script>
<script type="text/javascript">
@ -42,5 +43,4 @@
return this.name?"node_label_italic":"";
}
});
</script>

View File

@ -14,15 +14,16 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var RED = require("../../red/red");
var badwords = require('badwords');
function BadwordsNode(n) {
RED.nodes.createNode(this,n);
var node = this;
this.on("input", function(msg) {
if (badwords.ok(msg.payload)) { node.send(msg); }
if (typeof msg.payload == "string") {
if (badwords.ok(msg.payload)) { node.send(msg); }
}
});
}
RED.nodes.registerType("badwords",BadwordsNode);