Skip to content

TrayLayout: accept the escaped layout from the SVG command line - #977

Merged
florianfesti merged 1 commit into
florianfesti:masterfrom
cristianchiriac:traylayout-escaped-newlines
Oct 17, 2026
Merged

florianfesti merged 1 commit into
florianfesti:masterfrom
cristianchiriac:traylayout-escaped-newlines

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Fixes #973.

parseArgs stores a "Command line" in the SVG metadata. Its cliQuote() writes the layout's newlines as a literal \n, so the command fits on one line. TrayLayout.prepare() splits --layout only on real newlines, so running that command again reads the whole grid as one line and fails with ValueError: Need more than one wall in y direction.

prepare() now turns a literal \n back into a newline when the layout has no real newline, which is exactly the shape cliQuote() produces. A hand-written layout or a layout from the web form contains real newlines and is left untouched, and the layout characters never include a backslash. GridfinityTrayLayout inherits the fix. I left cliQuote() alone: it has no portable way to put a newline into a one-line shell command, since $'…' is bash-only and shlex can't parse it.

This is separate from #974, which changes the --layout default for #972. That PR also touches tests/test_traylayout.py, so whichever lands second may need a small merge.

Test: test_command_line_from_svg_can_be_run_again renders the layout and takes the stored metadata["cli"]. It asserts that the stored --layout argument contains a literal \n and no real newline, splits the command with shlex, and renders it again. The x, y, hwalls, vwalls and floors must match the original.

  • before: ValueError: Need more than one wall in y direction, the error from the issue
  • after: passes. The full suite has 205 passed and 9 skipped, and ruff check and mypy are clean on the changed files.

The "Command line" stored in the SVG writes the layout's newlines as a
literal \n so the command fits on one line. TrayLayout split the layout
only on real newlines, so running that command again read the whole grid
as one line and failed with "Need more than one wall in y direction".

Decode the literal \n when the layout contains no real newline.

Fixes #973
@florianfesti

Copy link
Copy Markdown
Owner

I am not quite sure what work flow you are using to need this. But it is the right thing to do - especially given that we do produce the CLI ourselves.

@florianfesti
florianfesti merged commit 1d6a383 into florianfesti:master Oct 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TrayLayout CLI command in SVG comment fails with ValueError

2 participants