11 KiB
Codebase Concerns
Analysis Date: 2026-03-03
Code Duplication
Regex pattern compilation duplicated across node classes:
- Issue: Both
StringStripNodeandStringMultiReplaceNodeimplement nearly identical regex pattern building logic formatch_whole_stringandpreserve_punctuationcombinations. - Files:
string_strip_node.pylines 52-72,string_multi_replace_node.pylines 59-75 - Impact: If regex patterns need adjustment (e.g., for new punctuation marks), changes must be made in multiple places, increasing maintenance burden and risk of inconsistency.
- Fix approach: Extract shared regex pattern building logic into a utility module
string_utils.pywith a function likebuild_replacement_pattern(search_str, match_whole_string, preserve_punctuation)that both nodes can use.
Text cleanup logic duplicated:
- Issue:
cleanup_text()method is defined identically in bothStringStripNodeandStringMultiReplaceNode. - Files:
string_strip_node.pylines 27-30,string_multi_replace_node.pylines 29-32 - Impact: Bug fixes to space normalization or punctuation handling require changes in two places.
- Fix approach: Move
cleanup_text()to a shared utility module.
Input Validation Gaps
No validation of replacement_delimiter parameter:
- Issue:
StringMultiReplaceNode.string_replace()accepts any string asreplacement_delimiter, including empty strings or strings not present in replacement_pairs. - Files:
string_multi_replace_node.pylines 34-80 - Impact: Empty delimiter could cause silent failures or unexpected behavior. No error message guides users on correct format.
- Fix approach: Add validation to check if
replacement_delimiteris non-empty and is actually present in at least one line ofreplacement_pairswhen non-empty pairs are provided. Return error message if invalid.
No null/None input handling:
- Issue: All nodes assume string inputs are valid. If ComfyUI passes
Noneor unexpected types, nodes will crash with unhelpful error messages. - Files: All node classes (e.g.,
string_strip_node.pyline 32) - Impact: Silent failures in ComfyUI workflows without clear error reporting.
- Fix approach: Add type checking and explicit error handling at method entry points.
Missing handling of extremely long strings:
- Issue: Regex operations on very large strings (e.g., multi-megabyte text) could cause performance issues or regex complexity bombs.
- Files: All regex-based nodes (
string_strip_node.py,string_multi_replace_node.py,string_contains_any_node.py) - Impact: Workflows processing large text files could hang or crash unexpectedly.
- Fix approach: Add length checks and document maximum recommended input size.
Pattern Matching Edge Cases
Incomplete word boundary handling:
- Issue: The
\bword boundary in regex (lines 55, 62 instring_strip_node.py) doesn't work correctly at string boundaries with Unicode characters, accented characters, or special symbols. - Files:
string_strip_node.pylines 52-72,string_multi_replace_node.pylines 59-75 - Impact: Matching whole words in non-English text or with special characters produces unexpected results.
- Fix approach: Document this limitation or switch to a more robust word boundary detection method that handles Unicode properly.
Regex special characters not escaped in match_whole_string=False:
- Issue: In
preserve_punctuation=Falsemode, the patternre.escape(search_str) + r'(?:[,;:.])?'(line 72 instring_multi_replace_node.py) may not handle all edge cases where the search string itself contains pattern-matching characters. - Files:
string_multi_replace_node.pylines 70-72,string_strip_node.pylines 64-65 - Impact: While
re.escape()is used, the added(?:[,;:.])?pattern creates assumptions about which punctuation marks follow matches. Other punctuation or symbols would not be handled. - Fix approach: Either document the supported punctuation list or provide an option to make punctuation removal more flexible.
Error Reporting
No error messages returned to user:
- Issue: Invalid inputs (malformed replacement pairs, empty delimiters, etc.) fail silently or with generic Python exceptions.
- Files: All node classes
- Impact: Users get no feedback about what went wrong. Debugging workflows is difficult.
- Fix approach: Return structured error messages or use ComfyUI's error reporting mechanism.
Regex compilation errors not caught:
- Issue: If a user's input accidentally creates an invalid regex pattern, the
re.compile()call (lines 74 instring_multi_replace_node.py, line 67 instring_strip_node.py) will raise an exception that crashes the node without a helpful message. - Files:
string_strip_node.pyline 67,string_multi_replace_node.pyline 74 - Impact: Even simple typos in user input cause workflow failures with unhelpful error messages.
- Fix approach: Wrap
re.compile()in try-except block and return meaningful error message.
Performance Considerations
Regex patterns compiled multiple times per execution:
- Issue: In
StringStripNode.string_strip(), patterns are compiled in a loop (line 67) and compiled separately in a list for each method call. For large lists of removals, this is inefficient. - Files:
string_strip_node.pylines 50-71 - Impact: Repeated calls with same removal patterns waste CPU cycles on recompilation.
- Fix approach: Consider memoizing compiled patterns if the same
strings_to_removeis used repeatedly, or compile once and reuse within a single call.
Sorting by length every execution:
- Issue: Strings are sorted by length on every method call (lines 44 in
string_strip_node.py, line 52 instring_multi_replace_node.py). This is necessary for correctness but could be optimized with caching if patterns are reused. - Files:
string_strip_node.pyline 44,string_multi_replace_node.pyline 52 - Impact: Minor performance impact for large replacement lists on repeated calls.
- Fix approach: Document the O(n log n) sorting behavior; consider caching if needed.
Testing Coverage Gaps
No tests for regex compilation failures:
- What's not tested: Invalid regex patterns that would cause
re.compile()to raise an exception. - Files:
string_strip_node.pyline 67,string_multi_replace_node.pyline 74,test_string_nodes.py - Risk: Unexpected regex patterns from user input could crash the node without warning.
- Priority: Medium
No tests for Unicode or special character handling:
- What's not tested: Input strings with emoji, accented characters, or multi-byte Unicode.
- Files:
test_string_nodes.py - Risk: Real-world prompts with special characters may behave unexpectedly.
- Priority: Medium
No tests for extreme input sizes:
- What's not tested: Very long strings (megabytes), very long replacement lists, very long individual replacement pairs.
- Files:
test_string_nodes.py - Risk: Performance issues or stack overflow on large inputs would not be detected.
- Priority: Low
No tests for StringTextboxNode:
- What's not tested: The
StringTextboxNode.pass_string()method has zero test coverage. - Files:
string_textbox_node.py,test_string_nodes.py - Risk: Changes to this node's behavior would go undetected.
- Priority: Low (simple pass-through, but should be covered)
No tests for StringPreviewNode:
- What's not tested: The
StringPreviewNode.preview_string()method and its specialIS_CHANGED()behavior. - Files:
string_preview_node.py,test_string_nodes.py - Risk: The
float("nan")return value inIS_CHANGED()is unusual and not validated. - Priority: Medium
Architecture Concerns
No base class for shared functionality:
- Issue: Six independent node classes with duplicated methods and patterns indicate missing abstraction.
- Files: All
*_node.pyfiles - Impact: Adding features (e.g., logging, input validation) requires changes to multiple files.
- Fix approach: Create a
BaseStringNodeclass with shared validation, error handling, and utility methods.
Inconsistent parameter naming:
- Issue:
StringStripNodeusesstrings_to_remove,StringMultiReplaceNodeusesreplacement_pairs, etc. Inconsistent naming makes workflows harder to understand and API harder to learn. - Files: All node classes
- Impact: Users must remember different parameter names for similar operations.
- Fix approach: Standardize parameter names across nodes or document the reasoning for differences.
Missing Features
No logging of transformations:
- Issue: Nodes silently perform transformations with no audit trail or debug output.
- Files: All node classes
- Impact: Users cannot see what replacements were actually made or debug complex workflows.
- Fix approach: Add optional debug output or logging parameter.
No reuse of previous results:
- Issue: Each node independently processes input; there's no way to chain results with visibility into intermediate states.
- Files: All output nodes
- Impact: Complex text processing requires many separate nodes instead of a single configurable pipeline.
- Fix approach: Consider a single "Text Processing Pipeline" node that chains multiple operations.
Potential Security Concerns
Regular expression denial of service (ReDoS) risk:
- Issue: User-provided input in
strings_to_remove,replacement_pairs, andsubstringsare used directly in regex patterns afterre.escape(). Whilere.escape()prevents most ReDoS, deeply nested or pathological patterns could still cause issues. - Files:
string_strip_node.pylines 52-72,string_multi_replace_node.pylines 59-75,string_contains_any_node.py(simple substring search, low risk) - Impact: Malicious or accidental input could cause CPU spike and freeze workflows.
- Fix approach: Add timeout to regex operations or limit complexity of patterns accepted.
Known Limitations
Word boundary matching fails with Unicode:
- The
\banchor in regex patterns doesn't correctly identify word boundaries in non-ASCII text. - Workaround: Test thoroughly with non-English text; consider providing separate "ASCII-only" and "Unicode-aware" modes.
Punctuation handling is opinionated:
- The hardcoded punctuation list
[,;:.]only handles common English punctuation. Other languages or contexts may use different marks. - Workaround: Make punctuation marks configurable, or document the list and allow users to add custom nodes for other punctuation.
Case-insensitive matching doesn't handle Unicode case folding:
- Python's
.lower()method handles most Unicode, but some edge cases in Turkish, Greek, and other languages may not be handled optimally. - Workaround: Document that case-insensitive matching is "best effort" for non-ASCII text.
Concerns audit: 2026-03-03