Download custom_nodes/ComfyUI-Pixaroma/scripts/save_prefix_check.py from AIPRIVATEGROUP/pgupscaler: direct link, hf CLI and curl.
- Browser
- Download file 6.07 kB
-
https://huggingface.co/AIPRIVATEGROUP/pgupscaler/resolve/main/custom_nodes/ComfyUI-Pixaroma/scripts/save_prefix_check.py
- Command line
-
hf download hf://AIPRIVATEGROUP/pgupscaler/custom_nodes/ComfyUI-Pixaroma/scripts/save_prefix_check.py
-
curl -L -o save_prefix_check.py https://huggingface.co/AIPRIVATEGROUP/pgupscaler/resolve/main/custom_nodes/ComfyUI-Pixaroma/scripts/save_prefix_check.py
6.07 kB
| """Check _safe_prefix (filename_prefix sanitizer) behavior. | |
| Run: python scripts/save_prefix_check.py | |
| Exits 0 on PREFIX PASS, 1 on any mismatch. | |
| Locks in the June-2026 fix for the Korean filename_prefix report: the | |
| sanitizer must only neutralize genuinely dangerous characters (Windows- | |
| illegal chars, control chars, path traversal) and let every other | |
| character through verbatim - non-Latin scripts, accented letters, and | |
| spaces included - matching native ComfyUI SaveImage, which does no | |
| character filtering at all (folder_paths.get_save_image_path only | |
| enforces that the final path stays inside output/). | |
| """ | |
| import os | |
| import sys | |
| import time | |
| # Import the helper directly off the nodes/ dir. Do NOT use `from nodes._save...` | |
| # - `nodes` collides with ComfyUI's top-level nodes.py when it's on sys.path. | |
| # _save_helpers.py has no relative imports, so loading it standalone is safe. | |
| sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "nodes")) | |
| from _save_helpers import _safe_prefix # noqa: E402 | |
| _today = time.strftime("%Y-%m-%d") | |
| _hour = time.strftime("%H") # 24-hour, zero-padded (what hh / HH must expand to) | |
| # (input, expected) - expected None means "unrecoverable, caller falls back" | |
| CASES = [ | |
| # ββ The reported Korean cases (parity with native SaveImage) ββββββββββ | |
| ("νλ‘μ νΈ/ν μ€νΈ/μ΄λ―Έμ§", "νλ‘μ νΈ/ν μ€νΈ/μ΄λ―Έμ§"), | |
| ("project/te μ€ st/image", "project/te μ€ st/image"), | |
| # ββ Unicode + spaces survive verbatim βββββββββββββββββββββββββββββββββ | |
| ("cafΓ©/naΓ―ve", "cafΓ©/naΓ―ve"), | |
| ("ζ₯ζ¬θͺ/η»ε", "ζ₯ζ¬θͺ/η»ε"), | |
| ("Bunny WithCubes - Copy.png", "Bunny WithCubes - Copy.png"), | |
| ("a b", "a b"), # interior spaces untouched | |
| (" padded /img", "padded/img"), # segment-edge whitespace trimmed | |
| # ββ Windows-illegal characters are neutralized to '_' βββββββββββββββββ | |
| ('a<b>c:d"e|f?g*h', "a_b_c_d_e_f_g_h"), | |
| ("a\tb", "a_b"), # control chars too | |
| # The drive colon becomes '_' and that '_' now SURVIVES, because the strip | |
| # is front-only since 2026-09-22 (see _sanitize_segment). Containment is | |
| # unchanged: the colon is still neutralized, so this stays a plain relative | |
| # segment inside the save folder. | |
| ("C:\\Users\\x", "C_/Users/x"), # drive colon -> '_', \ -> / | |
| # ββ Windows reserved device names get a '_' suffix ββββββββββββββββββββ | |
| ("CON/img", "CON_/img"), | |
| ("nul.txt/img", "nul.txt_/img"), | |
| ("com1", "com1_"), | |
| # ββ Windows trailing-dot/space rule (OS strips them silently) βββββββββ | |
| ("test.../img", "test/img"), | |
| ("teasda......////", "teasda"), # docstring example, must keep working | |
| # ββ Unchanged ASCII behavior (regression guards) ββββββββββββββββββββββ | |
| ("img", "img"), | |
| ("SDXL/portrait", "SDXL/portrait"), | |
| ("a__b", "a_b"), # underscore collapse retained | |
| ("???", None), # nothing usable -> fallback | |
| # ββ Underscores: FRONT stripped, TRAILING kept (2026-09-22) βββββββββββ | |
| # Reported: "Save Image Pixaroma I can't get the _". ComfyUI's own | |
| # SaveImage writes name_00001_.png and `name_%counter%_` silently lost the | |
| # underscore, with no way to get it back. A leading one is nearly always | |
| # the residue of a token that resolved to nothing, so that strip stays. | |
| ("_edge_", "edge_"), | |
| ("_lead", "lead"), # leading residue still tidied | |
| ("trail_", "trail_"), # THE REPORTED CASE | |
| ("name_%counter%_", "name_%counter%_"), # what the reporter types | |
| ("a/b_/c_", "a/b_/c_"), # per segment, not only the last | |
| ("_", None), # front strip leaves nothing | |
| ("__", None), # collapses to '_', then stripped | |
| ("x__", "x_"), # the run still collapses to one | |
| ("test._", "test._"), # legal: does not END in a dot | |
| # ββ Tokens ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| ("%date:yyyy-MM-dd%/img", _today + "/img"), | |
| ("%year%-%month%/img", "%year%-%month%/img"), # native tokens preserved | |
| # Hour token: native ComfyUI uses lowercase hh (24-hour). It must expand, | |
| # not come out literal. HH is kept as a backward-compat alias. | |
| ("%date:hh%/x", _hour + "/x"), | |
| ("%date:HH%/x", _hour + "/x"), | |
| ("%date:yyyy-MM-dd hh%", _today + " " + _hour), | |
| # ββ Traversal / absolute / garbage rejection (must stay rejected) βββββ | |
| ("../evil", None), | |
| ("a/../b", None), | |
| ("/absolute", None), | |
| ("", None), | |
| (" ", None), | |
| (None, None), | |
| (123, None), | |
| ("a" * 300, None), # input length cap | |
| ] | |
| def main(): | |
| failures = [] | |
| for raw, expected in CASES: | |
| got = _safe_prefix(raw) | |
| if got != expected: | |
| failures.append((raw, expected, got)) | |
| # Output-length cap: 121-char input truncates to 100 | |
| long_in = "x" * 60 + "/" + "y" * 60 | |
| long_got = _safe_prefix(long_in) | |
| if long_got is None or len(long_got) > 100 or not long_got.startswith("x" * 60 + "/"): | |
| failures.append((long_in, "<=100 chars keeping x.../y...", long_got)) | |
| if failures: | |
| print(f"PREFIX FAIL - {len(failures)} case(s):") | |
| for raw, expected, got in failures: | |
| # ascii() so a cp1252 Windows console can't choke on Korean output | |
| print(f" input={ascii(raw)}\n expected={ascii(expected)}\n got ={ascii(got)}") | |
| return 1 | |
| print(f"PREFIX PASS ({len(CASES) + 1} cases)") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |