fix(map): fail on blank rows inside a layer, keep trailing-space cells verbatim

This commit is contained in:
2026-09-20 17:48:47 +02:00
parent 205ddece0b
commit bce0a59e60
2 changed files with 46 additions and 4 deletions
+17 -4
View File
@@ -89,14 +89,27 @@ class _MapFile(BaseModel):
def _split_rows(block: str, what: str, path: Path) -> tuple[str, ...]:
rows = tuple(line.rstrip() for line in block.splitlines() if line.strip())
if not rows:
"""Split an ASCII layer into equal-width rows, failing loudly on gaps.
Trailing empty lines are a YAML block-scalar artifact and dropped; an
empty line *inside* the layer is a missing row -- a data error, never a
silently dropped one. Rows are kept verbatim (no rstrip): trailing spaces
are cells whenever " " is in the legend, and the width/char checks catch
them otherwise.
"""
lines = block.splitlines()
while lines and lines[-1] == "":
lines.pop()
if not lines:
msg = f"{what} layer is empty"
raise MapValidationError(path, msg)
if len({len(row) for row in rows}) != 1:
if any(line == "" for line in lines):
msg = f"{what} layer has a blank row inside the layer"
raise MapValidationError(path, msg)
if len({len(row) for row in lines}) != 1:
msg = f"{what} layer has ragged rows"
raise MapValidationError(path, msg)
return rows
return tuple(lines)
def _check_layer_dimensions(