fix: parse_sigmas rejects trailing/leading/double commas

This commit is contained in:
Jason Hoku
2026-04-25 16:39:34 -07:00
parent 1ea4d7892d
commit 69830a3aef
2 changed files with 22 additions and 1 deletions
+7 -1
View File
@@ -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)
+15
View File
@@ -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")