diff --git a/pyproject.toml b/pyproject.toml index 190d699..48f4929 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_stringessentials" description = "Simple string manipulation nodes for ComfyUI (strip/remove text strings, search and replace text strings, preview modified string outputs). Useful for modifying text prompts or results from LLM outputs. Nodes will be located under standard Add Node > utils menu. Node names: String Textbox, String Strip, String Multi Replace, String Conditional Append and String Preview." -version = "2.0.3" +version = "2.0.4" license = {file = "LICENSE"} [project.urls] diff --git a/string_multi_replace_node.py b/string_multi_replace_node.py index d6c0dad..236120f 100644 --- a/string_multi_replace_node.py +++ b/string_multi_replace_node.py @@ -35,13 +35,13 @@ class StringMultiReplaceNode: # Create a list of all replacements replacements = [] for line in replacement_pairs.splitlines(): - line = line.strip() - if not line or replacement_delimiter not in line: + # Don't strip the line yet to preserve trailing whitespace in replacements (Issue #8) + if not line or line.isspace() or replacement_delimiter not in line: continue search_str, replace_str = line.split(replacement_delimiter, 1) search_str = search_str.strip() - replace_str = replace_str.strip() + # Don't strip replace_str to allow intentional spaces/whitespace (Issue #8) if not search_str: continue diff --git a/test_string_nodes.py b/test_string_nodes.py index 276c159..a209f67 100644 --- a/test_string_nodes.py +++ b/test_string_nodes.py @@ -344,5 +344,65 @@ goodbye""" self.assertEqual(result, "Hello world goodbye") self.assertFalse(was_appended) + def test_replace_with_space(self): + # Test Issue #8: Replace with space (trailing space should be preserved) + input_string = "hello_world_test" + replacement_pairs = "_:: " + result = self.replace_node.string_replace( + input_string=input_string, + replacement_pairs=replacement_pairs, + replacement_delimiter="::", + match_case=False, + match_whole_string=False, + preserve_punctuation=True, + remove_extra_spaces=False + )[0] + self.assertEqual(result, "hello world test") + + def test_replace_with_leading_space(self): + # Test Issue #8: Replace with leading space + input_string = "value1,value2,value3" + replacement_pairs = ",::, " + result = self.replace_node.string_replace( + input_string=input_string, + replacement_pairs=replacement_pairs, + replacement_delimiter="::", + match_case=False, + match_whole_string=False, + preserve_punctuation=True, + remove_extra_spaces=False + )[0] + self.assertEqual(result, "value1, value2, value3") + + def test_replace_with_whitespace_only(self): + # Test Issue #8: Replace with only whitespace + input_string = "word1___word2" + replacement_pairs = "___:: " + result = self.replace_node.string_replace( + input_string=input_string, + replacement_pairs=replacement_pairs, + replacement_delimiter="::", + match_case=False, + match_whole_string=False, + preserve_punctuation=True, + remove_extra_spaces=False + )[0] + self.assertEqual(result, "word1 word2") + + def test_replace_with_tab(self): + # Test Issue #8: Replace with tab character + input_string = "column1|column2|column3" + replacement_pairs = "|::\t" + result = self.replace_node.string_replace( + input_string=input_string, + replacement_pairs=replacement_pairs, + replacement_delimiter="::", + match_case=False, + match_whole_string=False, + preserve_punctuation=True, + remove_extra_spaces=False + )[0] + self.assertEqual(result, "column1\tcolumn2\tcolumn3") + if __name__ == '__main__': unittest.main() \ No newline at end of file