Skip to content

fix(format): refuse unwritable quantities in cooklang source - #738

Closed
drawmeanelephant wants to merge 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/722-negative-quantities
Closed

drawmeanelephant wants to merge 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/722-negative-quantities

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #722

A recipe scaled below zero emitted @flour{-400%g}, which reparses as {"type":"text","value":"-400","scalable":false} — the quantity silently stops scaling and aggregating. The grammar has no negative (or non-finite) numeric literal, so the formatter now rejects such quantities with cannot write quantity '-400' as cooklang source instead of corrupting the recipe.

Test plan

  • new test a_negative_quantity_fails_the_format
  • cargo test -p cooklang-format green (35 tests)
  • cook recipe neg.cook --scale=-1 -f cooklang → clean error, exit 1

A recipe scaled below zero emitted `@flour{-400%g}`, which reparses as
a *text* quantity — silently non-scalable and non-aggregating. There is
no source form for a negative (or non-finite) number, so the formatter
now fails with an error instead of corrupting the recipe.

Closes #722
@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Superseded by #755, which fixes the same defect more completely: it refuses before any output is written (this version could emit a partial recipe first) and also covers positive Range and Fraction values, which likewise cannot parse back under Extensions::empty().

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.

Negative quantities round-trip through cooklang format as non-scalable text

1 participant