fix: reject a configuration entry with an empty value1
A line such as "=z" parsed into the pair ("", "z"). An empty value1
matches at every position and consumes nothing, so the scan in
replace_line never advanced and the program looped forever, printing
nothing and growing its output buffer until it was killed.
Reject the entry while parsing, reporting the offending line the same
way as a line with no "=" at all, and document the termination
invariant the loop depends on.
This commit is contained in:
@@ -18,6 +18,15 @@ def load_config(filename: str) -> list[tuple[str, str]]:
|
||||
)
|
||||
|
||||
value1, value2 = line.split("=", 1)
|
||||
|
||||
# An empty value1 would match at every position without
|
||||
# consuming anything, leaving replace_line unable to advance.
|
||||
if not value1:
|
||||
raise ValueError(
|
||||
f"Invalid configuration at line {line_number}: {line!r} "
|
||||
f"(the value to replace must not be empty)"
|
||||
)
|
||||
|
||||
pairs.append((value1, value2))
|
||||
|
||||
return pairs
|
||||
Reference in New Issue
Block a user