From ba31c503b5861be1e511e35cacaaf747c85d8e50 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 6 Aug 2026 11:35:37 +0000 Subject: [PATCH] Keep folder prefix in strip iteration node --- README.md | 4 ++-- dumas_json_nodes.py | 2 +- tests/test_dumas_json_nodes.py | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 98e54a7..cffdf6c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ - `Dumas Strip Iteration Suffix` - Input: `filename` - Output: cleaned `STRING` - - Removes the final underscore segment before the file extension, for example `asset_003.png -> asset.png` and `char123_pose.png -> char123.png`. + - Keeps only the part before the first underscore, for example `asset_build_003.png -> asset.png` and `char123_pose.png -> char123.png`. - `Dumas Slugify String` - Input: `text` @@ -170,7 +170,7 @@ decr -> use index - 1 `Save Image Dumas` leaves `folder` empty to use ComfyUI's output directory. `name` feeds `%input%` and `name_2` feeds `%input2%`, so a pattern like `project/%input%_%input2%_%counter%` can combine two upstream strings into the saved filename. -`Dumas Strip Iteration Suffix` strips everything after the last underscore, plus that underscore itself. Names like `my_asset_final.png` become `my_asset.png`, while names with no underscore such as `char123.png` are left untouched. +`Dumas Strip Iteration Suffix` keeps the part before the first underscore and drops the rest. Names like `char123_pose_final.png` become `char123.png`, while names with no underscore such as `char123.png` are left untouched. `Dumas Slugify String` lowercases text, strips accents, replaces non-alphanumeric runs with `-`, and trims leading or trailing dashes. diff --git a/dumas_json_nodes.py b/dumas_json_nodes.py index 4ccde92..2e0d2fd 100644 --- a/dumas_json_nodes.py +++ b/dumas_json_nodes.py @@ -254,7 +254,7 @@ def _strip_iteration_suffix(value): if "_" not in root: return value - prefix, _suffix = root.rsplit("_", 1) + prefix, _suffix = root.split("_", 1) return f"{prefix}{extension}" diff --git a/tests/test_dumas_json_nodes.py b/tests/test_dumas_json_nodes.py index 682ad6d..d57a312 100644 --- a/tests/test_dumas_json_nodes.py +++ b/tests/test_dumas_json_nodes.py @@ -43,26 +43,26 @@ class DumasJSONNodeTests(unittest.TestCase): self.assertEqual(result, ('{\n "a": 2,\n "b": 1\n}',)) - def test_strip_iteration_suffix_removes_trailing_iteration_before_extension(self): + def test_strip_iteration_suffix_keeps_only_prefix_before_first_underscore(self): node = DumasStripIterationSuffixNode() result = node.strip_iteration_suffix("asset_build_003.png") - self.assertEqual(result, ("asset_build.png",)) + self.assertEqual(result, ("asset.png",)) - def test_strip_iteration_suffix_removes_trailing_iteration_without_extension(self): + def test_strip_iteration_suffix_keeps_only_prefix_without_extension(self): node = DumasStripIterationSuffixNode() result = node.strip_iteration_suffix("asset_build_003") - self.assertEqual(result, ("asset_build",)) + self.assertEqual(result, ("asset",)) - def test_strip_iteration_suffix_removes_last_underscore_segment_even_when_not_numeric(self): + def test_strip_iteration_suffix_removes_everything_after_first_underscore(self): node = DumasStripIterationSuffixNode() - result = node.strip_iteration_suffix("my_asset_final.png") + result = node.strip_iteration_suffix("char123_pose_final.png") - self.assertEqual(result, ("my_asset.png",)) + self.assertEqual(result, ("char123.png",)) def test_strip_iteration_suffix_leaves_names_without_underscore_unchanged(self): node = DumasStripIterationSuffixNode()