-
-
Notifications
You must be signed in to change notification settings - Fork 23.7k
fix: implement regex operation handler in Condition node #5734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The Condition Agentflow node offered a 'Regex' option in the frontend dropdown, but compareOperationFunctions did not include a regex handler. This caused a runtime error: compareOperationFunctions[operation] is not a function Added a regex handler that tests value1 against the regex pattern in value2 using RegExp. Invalid regex patterns gracefully return false instead of throwing. Fixes FlowiseAI#5650
Summary of ChangesHello @themavik, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a functional gap in the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly implements the missing regex operation handler for the Condition node, fixing a crash. The use of a try/catch block is a good practice for handling potentially invalid regular expressions from user input. I've suggested a minor improvement to make the value handling more robust and consistent with other operators, particularly for null and undefined inputs.
| startsWith: (value1: CommonType, value2: CommonType) => (value1 as string).startsWith(value2 as string), | ||
| regex: (value1: CommonType, value2: CommonType) => { | ||
| try { | ||
| return new RegExp(value2 as string).test((value1 || '').toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type casting value2 as string can lead to unexpected behavior if value2 is null or undefined. For example, new RegExp(null) creates a regular expression /null/, which is likely not the intended behavior. To handle null and undefined values gracefully and align with other operators like contains, it's better to convert value2 to a string, treating null or undefined as an empty string. The same can be applied to value1 for consistency and clarity.
| return new RegExp(value2 as string).test((value1 || '').toString()) | |
| return new RegExp(String(value2 ?? '')).test(String(value1 ?? '')) |
Summary
Fixes #5650
The Condition Agentflow node defines a Regex option in the frontend dropdown (line 101-102), but
compareOperationFunctionsdid not include aregexhandler. This caused:Changes
packages/components/nodes/agentflow/Condition/Condition.ts: Addedregexhandler tocompareOperationFunctions. The handler usesnew RegExp(value2).test(value1)wrapped in try/catch to gracefully handle invalid regex patterns.Risk Assessment
Low - Only adds a missing handler. Existing operations are unchanged.