fix: parse_sigmas rejects trailing/leading/double commas
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user