fix: implement regex operation in Condition node#5711
fix: implement regex operation in Condition node#5711thecaptain789 wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
The 'Regex' operation was available in the frontend dropdown but not implemented in the backend's compareOperationFunctions map, causing a runtime error when used. Added regex handler that: - Creates a RegExp from the value2 pattern - Tests value1 against the pattern - Returns false if the regex pattern is invalid (graceful error handling) Fixes FlowiseAI#5650
Summary of ChangesHello @thecaptain789, 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 resolves a critical issue where the 'Regex' operation, despite being available in the frontend for Condition nodes, was not implemented in the backend's 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.
Code Review
This pull request correctly implements the missing regex operation for the Condition node, resolving a runtime error. The implementation gracefully handles invalid regex patterns by returning false. I've added a suggestion to further improve the robustness of the type handling and to enhance debuggability by logging errors from invalid patterns.
| regex: (value1: CommonType, value2: CommonType) => { | ||
| try { | ||
| const pattern = new RegExp(value2 as string) | ||
| return pattern.test((value1 || '').toString()) | ||
| } catch { | ||
| return false | ||
| } | ||
| }, |
There was a problem hiding this comment.
This is a good implementation. I have a couple of suggestions to make it even more robust and easier to debug:
- Safer Type Handling:
value2is of typeCommonTypeand can benull.new RegExp(null)creates a regex for the literal string "null", which is likely not intended. Convertingvalue2to a string explicitly (withnullorundefinedbecoming an empty string) is safer and more predictable. - Error Logging: The empty
catchblock 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.
| 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 | |
| } | |
| }, |
|
we have a similar PR |
Description
The 'Regex' operation was available in the frontend dropdown for Condition nodes but was not implemented in the backend's
compareOperationFunctionsmap. This caused a runtime error:compareOperationFunctions[operation] is not a function.Root Cause
regexoption is defined in the frontend optionscompareOperationFunctionsobject did NOT include aregexhandlerSolution
Added a
regexhandler to thecompareOperationFunctionsmap that:RegExpfrom the value2 patternpattern.test()falsegracefully if the regex pattern is invalid (try/catch)Changes
Testing
Related Issue
Fixes #5650