From 69830a3aeff8697c74b92e8edd92b86fedc357d9 Mon Sep 17 00:00:00 2001 From: Jason Hoku Date: Sat, 25 Apr 2026 16:39:34 -0700 Subject: [PATCH] fix: parse_sigmas rejects trailing/leading/double commas --- ltx_video_generation.py | 8 +++++++- tests/test_ltx_sigma_parser.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ltx_video_generation.py b/ltx_video_generation.py index 351e159..42cd2be 100644 --- a/ltx_video_generation.py +++ b/ltx_video_generation.py @@ -55,7 +55,13 @@ def parse_sigmas(sigma_str): if not sigma_str or not sigma_str.strip(): raise ValueError("Sigma string is empty") - tokens = [t.strip() for t in sigma_str.split(",") if t.strip()] + tokens = [t.strip() for t in sigma_str.split(",")] + # Reject empty tokens (catches trailing/leading/double commas) + for tok in tokens: + if not tok: + raise ValueError( + "Sigma string has an empty token (trailing/leading/double comma): " + repr(sigma_str) + ) if len(tokens) < 2: raise ValueError( "Sigma string must contain at least 2 comma-separated values, got: " + repr(sigma_str) diff --git a/tests/test_ltx_sigma_parser.py b/tests/test_ltx_sigma_parser.py index 935e824..825fb1f 100644 --- a/tests/test_ltx_sigma_parser.py +++ b/tests/test_ltx_sigma_parser.py @@ -30,3 +30,18 @@ def test_parse_empty_raises(): def test_parse_malformed_raises(): with pytest.raises(ValueError, match="not a valid float"): parse_sigmas("1.0, abc, 0.0") + + +def test_parse_trailing_comma_raises(): + with pytest.raises(ValueError, match="empty token"): + parse_sigmas("1.0, 0.5, 0.0,") + + +def test_parse_leading_comma_raises(): + with pytest.raises(ValueError, match="empty token"): + parse_sigmas(", 1.0, 0.5, 0.0") + + +def test_parse_double_comma_raises(): + with pytest.raises(ValueError, match="empty token"): + parse_sigmas("1.0,, 0.5, 0.0")