mirror of https://github.com/node-red/node-red.git
Remove UI option to return regex matches
always return msg.matches for a regex.add-switch-regex-option-to-return-matches
parent
e71bfbd8ca
commit
78fa6d81cb
|
|
@ -112,7 +112,6 @@
|
|||
}
|
||||
if (type === "regex") {
|
||||
r.case = rule.find(".node-input-rule-case").prop("checked");
|
||||
r.match = rule.find(".node-input-rule-match").prop("checked");
|
||||
}
|
||||
}
|
||||
return r;
|
||||
|
|
@ -236,7 +235,6 @@
|
|||
|
||||
var andLabel = this._("switch.and");
|
||||
var caseLabel = this._("switch.ignorecase");
|
||||
var matchLabel = this._("switch.returnmatches");
|
||||
|
||||
$("#node-input-rule-container").css('min-height','150px').css('min-width','450px').editableList({
|
||||
addItem: function(container,i,opt) {
|
||||
|
|
@ -303,7 +301,6 @@
|
|||
|
||||
var rowInputCell = $('<div>',{style:"flex-grow:1; margin-left: 5px;"}).appendTo(row);
|
||||
|
||||
|
||||
var valueField = null;
|
||||
var numValueField = null;
|
||||
var expValueField = null;
|
||||
|
|
@ -317,8 +314,6 @@
|
|||
|
||||
var caseSensitive = $('<input/>',{id:"node-input-rule-case-"+i,class:"node-input-rule-case",type:"checkbox",style:"width:auto;vertical-align:top"}).appendTo(row2);
|
||||
$('<label/>',{for:"node-input-rule-case-"+i,style:"margin-left: 3px;"}).text(caseLabel).appendTo(row2);
|
||||
var returnMatch = $('<input/>',{id:"node-input-rule-match-"+i,class:"node-input-rule-match",type:"checkbox",style:"width:auto;vertical-align:top"}).appendTo(row2);
|
||||
$('<label/>',{for:"node-input-rule-match-"+i,style:"margin-left: 3px;"}).text(matchLabel).appendTo(row2);
|
||||
|
||||
selectField.on("change", function() {
|
||||
var fieldToFocus;
|
||||
|
|
@ -423,7 +418,6 @@
|
|||
valueField.typedInput('value',rule.v);
|
||||
}
|
||||
caseSensitive.prop('checked',!!rule.case);
|
||||
returnMatch.prop('checked',!!rule.match);
|
||||
selectField.change();
|
||||
|
||||
var currentOutputs = JSON.parse(outputCount.val()||"{}");
|
||||
|
|
|
|||
|
|
@ -30,10 +30,7 @@ module.exports = function(RED) {
|
|||
'false': function(a) { return a === false; },
|
||||
'null': function(a) { return (typeof a == "undefined" || a === null); },
|
||||
'nnull': function(a) { return (typeof a != "undefined" && a !== null); },
|
||||
'regex': function(a, b, c, d, e, f) {
|
||||
if (f) { return (a + "").matchAll(new RegExp(b,d?'ig':'g')); }
|
||||
else { return (a + "").match(new RegExp(b,d?'i':'')); }
|
||||
},
|
||||
'regex': function(a, b, c, d) { return (a + "").matchAll(new RegExp(b,d?'ig':'g')); },
|
||||
'empty': function(a) {
|
||||
if (typeof a === 'string' || Array.isArray(a) || Buffer.isBuffer(a)) {
|
||||
return a.length === 0;
|
||||
|
|
@ -200,9 +197,9 @@ module.exports = function(RED) {
|
|||
state.elseflag = true;
|
||||
}
|
||||
try {
|
||||
const r = operators[rule.t](property,v1,v2,rule.case,msg.parts,rule.match )
|
||||
const r = operators[rule.t](property,v1,v2,rule.case,msg.parts)
|
||||
if (r) {
|
||||
if (rule.match == true && rule.t === "regex") {
|
||||
if (rule.t === "regex") {
|
||||
msg.matches = [];
|
||||
for (const match of r) {
|
||||
const le = match.length
|
||||
|
|
|
|||
|
|
@ -760,7 +760,6 @@
|
|||
"checkall": "checking all rules",
|
||||
"stopfirst": "stopping after first match",
|
||||
"ignorecase": "ignore case",
|
||||
"returnmatches": "return msg.matches",
|
||||
"rules": {
|
||||
"btwn": "is between",
|
||||
"cont": "contains",
|
||||
|
|
|
|||
|
|
@ -469,14 +469,14 @@ describe('switch Node', function() {
|
|||
customFlowSwitchTest(flow, true, "oneTWOthree", done);
|
||||
});
|
||||
|
||||
it('should match regex with return-matches flag set true', function(done) {
|
||||
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"(b[aio]..)","vt":"str","match":true}],checkall:true,outputs:1,wires:[["helperNode1"]]},
|
||||
it('should match regex and return matches', function(done) {
|
||||
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"(b[aio]..)","vt":"str"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
customFlowMessageSwitchTest(flow, true, {payload:"foobishbashboshpoo",matches:[{"match":"bish","index":3,"groups":["bish"]},{"match":"bash","index":7,"groups":["bash"]},{"match":"bosh","index":11,"groups":["bosh"]}]}, done);
|
||||
});
|
||||
|
||||
it('should match regex with return-matches flag set true - 2', function(done) {
|
||||
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"[b][iao]","vt":"str","match":true}],checkall:true,outputs:1,wires:[["helperNode1"]]},
|
||||
it('should match regex and return matches - 2', function(done) {
|
||||
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"[b][iao]","vt":"str"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
customFlowMessageSwitchTest(flow, true, {payload:"foobishbashboshpoo",matches:[{"match":"bi","index":3,"groups":[]},{"match":"ba","index":7,"groups":[]},{"match":"bo","index":11,"groups":[]}]}, done);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue