Skip to content

cooklang format wraps lines inside hyphenated components, corrupting names on reparse #700

Closed

Description

@drawmeanelephant

Suggested labels: bug, area: cli


Discovery audit finding M3 (medium) — cooklang/cookcli @ 7c2f48b (v0.38.1), audited 2026-10-12. Repro verified. Round-trip corruption.

Summary

--format cooklang wraps lines inside hyphenated components, corrupting ingredient names on reparse.

Where

crates/format/src/cooklang_source.rs:171-177 — textwrap runs with the default WordSplitter::HyphenSplitter, which splits the "component words" that component_word_separator (:196-241) carefully keeps whole. Fix is .word_splitter(WordSplitter::NoHyphenation). Wrap width is also terminal-dependent (termwidth().min(80)).

Repro

Input step: Mix @all-purpose flour{1%cup} with @super-fine caster sugar{2%tbsp} and @extra-virgin olive oil{1%tbsp} ...

Output breaks as @extra-\nvirgin olive oil{1%tbsp}; reparsing yields ingredient extra- virgin olive oil (name changed → shopping-list/aisle matching changes). Plain text corrupts too: well-known → well- known.

Expected

--format cooklang output reparses to the same recipe (names unchanged).

Actual

Hyphenated component words are split across lines; reparse produces a different ingredient name.

Acceptance criteria (red → green)

  • Red: the repro's output contains @extra-\nvirgin and reparses to extra- virgin olive oil.
  • Green: reparse of the formatted output yields the identical ingredient name (extra-virgin olive oil).

Verification

Executed repro.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions