diff --git a/dumas_image_nodes.py b/dumas_image_nodes.py index fa096d3..52b8ce6 100644 --- a/dumas_image_nodes.py +++ b/dumas_image_nodes.py @@ -95,6 +95,13 @@ def _safe_pattern(value): return value +def _is_within_directory(parent_path, child_path): + try: + return os.path.commonpath([parent_path, child_path]) == parent_path + except ValueError: + return False + + def _next_counter(directory, filename_template): os.makedirs(directory, exist_ok=True) if "%counter%" not in filename_template: @@ -356,7 +363,7 @@ class DumasSaveImageNode: pnginfo = _build_pnginfo(prompt=prompt, extra_pnginfo=extra_pnginfo) image.save(full_path, "PNG", pnginfo=pnginfo) - if os.path.commonpath([output_dir, full_path]) == output_dir: + if _is_within_directory(output_dir, full_path): subfolder = os.path.relpath(frame_dir, output_dir) ui_images.append( { diff --git a/tests/test_dumas_image_nodes.py b/tests/test_dumas_image_nodes.py index fc2d9ce..69143a2 100644 --- a/tests/test_dumas_image_nodes.py +++ b/tests/test_dumas_image_nodes.py @@ -4,6 +4,7 @@ import sys import tempfile import types import unittest +from unittest import mock class FakeImageArray: @@ -185,6 +186,32 @@ class DumasImageNodeTests(unittest.TestCase): self.assertEqual(result["ui"]["images"][0]["type"], "external") self.assertEqual(result["ui"]["images"][0]["subfolder"], external_dir.replace("\\", "/")) + def test_save_image_handles_windows_different_drive_paths(self): + node = self.image_nodes.DumasSaveImageNode() + image = FakeTensorBatch() + + with mock.patch.object( + self.image_nodes.folder_paths, + "get_output_directory", + return_value="C:\\ComfyUI\\output", + ), mock.patch.object( + self.image_nodes.os.path, + "abspath", + return_value="D:\\renders", + ): + result = node.save_images( + images=image, + folder="D:\\renders", + pattern="drive_%counter%", + format="png", + quality=100, + embed_workflow=False, + save_on_run=True, + ) + + self.assertEqual(result["ui"]["images"][0]["type"], "external") + self.assertEqual(result["ui"]["images"][0]["subfolder"], "D:/renders") + def test_save_image_skips_when_save_is_disabled(self): node = self.image_nodes.DumasSaveImageNode() image = FakeTensorBatch()