Skip to content

fix: quote pantry section names containing spaces in TOML output - #296

Merged
dubadub merged 2 commits into
mainfrom
fix/pantry-section-name-quoting
Apr 2, 2026
Merged

dubadub merged 2 commits into
mainfrom
fix/pantry-section-name-quoting

Conversation

@dubadub

@dubadub dubadub commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Pantry section names containing spaces (e.g. ["Garage Freezer"]) were written without quotes during add/remove/edit operations, corrupting pantry.conf
  • Applied toml_escape_key() to section name serialization in both src/server/handlers/pantry.rs and src/pantry.rs, matching the escaping already used for item keys

Fixes #292

Test plan

  • Create a pantry.conf with a section like ["Garage Freezer"]
  • Use cook server to add/edit/remove items in that section
  • Verify section name retains quotes after modification
  • Verify sections without spaces still work correctly

Section names with spaces (e.g. "Garage Freezer") were written without
quotes, producing invalid TOML and corrupting pantry.conf on add/remove/
edit operations. Use toml_escape_key() for section headers, matching
the existing escaping already applied to item keys.

Fixes #292
@claude

claude Bot commented Apr 2, 2026

Copy link
Copy Markdown

test comment

The "spice rack" section was written as [spice rack] which is invalid
TOML — section names containing spaces must be quoted. This caused the
entire pantry.conf to fail parsing, making the pantry appear empty in
the web UI.
@claude

claude Bot commented Apr 2, 2026

Copy link
Copy Markdown

Code Review

Summary: Clean, minimal fix for a real data-corruption bug. The root cause is clear and both serialization paths are correctly patched.

What works well

  • Correctly applies the existing toml_escape_key() helper — no new logic needed, just consistent usage.
  • Both serialization sites (src/pantry.rs and src/server/handlers/pantry.rs) are updated symmetrically, so CLI and web UI behave the same.
  • The seed file fix (seed/config/pantry.conf) ensures new users are not immediately hit by the same invalid TOML on first run.
  • Commit messages are clear and explain both what broke and why.

Minor observations

Duplicated toml_escape_key function (pre-existing, not introduced here): The function is defined identically in both src/pantry.rs:90 and src/server/handlers/pantry.rs:443. Worth extracting to a shared utility (e.g., src/util/) in a follow-up to avoid future drift. The slightly different comments between the two copies already hint at this risk.

Incomplete special-character coverage in toml_escape_key (pre-existing): The function only quotes keys containing spaces, ., [, ]. TOML bare keys also prohibit characters like =, control characters, etc. For realistic pantry section names this is unlikely to matter, but it is a latent correctness gap. A follow-up could use a stricter allowlist (alphanumeric, -, _ only) or delegate to a TOML library for serialization.

No automated tests — acknowledged in CLAUDE.md as the current project state. The manual test plan in the PR description is adequate for now.

Verdict

The fix is correct and well-scoped. The two observations above are pre-existing issues and do not block merging. Good to go.

@dubadub
dubadub merged commit 7eb7c0c into main Apr 2, 2026
4 checks passed
@dubadub
dubadub deleted the fix/pantry-section-name-quoting branch April 2, 2026 15:50
@claude

claude Bot commented Apr 2, 2026

Copy link
Copy Markdown

Review: fix: quote pantry section names containing spaces in TOML output

Summary: Correct, minimal fix for a real TOML serialization bug. The change is consistent with the existing pattern already applied to item keys.

What is Good:

  • Applies toml_escape_key() symmetrically in both src/pantry.rs and src/server/handlers/pantry.rs, so both code paths are now consistent.
  • Fixes the seed pantry.conf to use valid TOML, which means the bug would have been immediately visible to any new user running cook seed.
  • Commit messages are clear and explain the root cause well.

Minor Observations:

  1. toml_escape_key() only quotes for spaces, dots, and brackets (src/pantry.rs:91-95, src/server/handlers/pantry.rs:443-447). The TOML spec requires quoting for more characters (e.g. backslashes, control characters). This is pre-existing and not introduced by this PR, but a follow-up to use a proper TOML serialization library for key escaping would make this more robust.

  2. Duplicate toml_escape_key() function: The identical function is defined in both src/pantry.rs:90 and src/server/handlers/pantry.rs:443. Pre-existing issue; a shared utility in src/util/ would eliminate the duplication.

Verdict: The fix is correct and safe to merge. The observations above are pre-existing issues not introduced here.

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.

Problem in pantry when section name contains space

1 participant