Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/components/nodes/agentflow/Condition/Condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ class Condition_Agentflow implements INode {
smaller: (value1: CommonType, value2: CommonType) => (Number(value1) || 0) < (Number(value2) || 0),
smallerEqual: (value1: CommonType, value2: CommonType) => (Number(value1) || 0) <= (Number(value2) || 0),
startsWith: (value1: CommonType, value2: CommonType) => (value1 as string).startsWith(value2 as string),
regex: (value1: CommonType, value2: CommonType) => {
try {
const pattern = new RegExp(String(value2 ?? ''))
return pattern.test((value1 || '').toString())
} catch {
return false
}
},
Comment on lines +278 to +285
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a good implementation. I have a couple of suggestions to make it even more robust and easier to debug:

  1. Safer Type Handling: value2 is of type CommonType and can be null. new RegExp(null) creates a regex for the literal string "null", which is likely not intended. Converting value2 to a string explicitly (with null or undefined becoming an empty string) is safer and more predictable.
  2. Error Logging: The empty catch block hides errors from invalid regex patterns. Logging the error provides a hook for easier debugging in the future if users report issues with their regex patterns.
Suggested change
regex: (value1: CommonType, value2: CommonType) => {
try {
const pattern = new RegExp(value2 as string)
return pattern.test((value1 || '').toString())
} catch {
return false
}
},
regex: (value1: CommonType, value2: CommonType) => {
try {
const pattern = new RegExp(String(value2 ?? ''))
return pattern.test((value1 || '').toString())
} catch (e) {
// For debugging, consider logging the error.
// console.error(`[Condition Node] Invalid regex pattern: "${value2}"`, e);
return false
}
},

isEmpty: (value1: CommonType) => [undefined, null, ''].includes(value1 as string),
notEmpty: (value1: CommonType) => ![undefined, null, ''].includes(value1 as string)
}
Expand Down