Repository navigation
fix(zpl): emit ^CI28, a ^CF default font and ^FH escaping in list labels - #56
Merged
Merged
Conversation
Closes #53. - ListLayout: emit ^CI28 (UTF-8) in the prologue. Without it the printer is not in UTF-8 mode and any non-ASCII input prints as garbage -- "café piña jalapeño" came out as "caf├® pi▨a jalape▨o". Reachable with ordinary input, since labelprint reads arbitrary text on stdin. - ListLayout: set the item font once with ^CF0,h,h instead of repeating ^A0N,h,h on every row. Only headers still carry their own ^A0N, since ^A is scoped to its own field and the next item falls back to ^CF. Removes one command per item row. - ListLayout: replace sanitized() -- which deleted ^ and ~ outright, silently corrupting the user's text -- with escaped() under ^FH, so they print as the real characters via _5E/_7E. Same protection, no data loss. The issue lists three escapes but there are four: _ is ^FH's own escape introducer, so a literal underscore must become _5F or it silently eats the next two characters. "snake_case_item" would have been corrupted. ReminderList.generate_label hand-rolled a second, weaker copy of this layout: it never sanitized at all, so a reminder titled "pay ^XZ rent" emitted a second ^XZ and terminated the label early, dropping every row below it. It now delegates to ListLayout(itemIndent: 80), which keeps the historical left margin and the derived ^PW1200 it hardcoded, and picks up all four fixes. Drops ~30 lines of parallel geometry code. Adds a ReminderListTests target (mirroring LabelPrintTests) -- the example had no coverage before. Verified against Labelary, the reference renderer: accents correct, ^ and ~ printed literally without truncating the label, underscores preserved, and the header's ^A0N does not leak into following items. swift build && swift test: Build complete!, 123 tests / 26 suites passed (110 / 25 before).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #53.
The three fixes (
Sources/LabelKit/Labels/ListLayout.swift)The prologue becomes
^XA^CI28^PW1200^LH0,0^LS0^CF0,50,50^LL…; item rows drop their font command, headers keep theirs.^CI28^A0N,50,50^FO100,90^FDeggs^FS^FO100,90^FH^FDeggs^FS^A0N,60,60^FO60,100^FDCostco:^FS^A0N,60,60^FO60,100^FH^FDCostco:^FS^/~in text_5E/_7E^Ais scoped to its own field, so a header's^A0Ndoes not leak into the items below it — that is what makes the^CFfix safe. Confirmed empirically, not assumed (see Verification).A fourth escape the issue didn't list
_is^FH's own escape introducer. Left alone it silently consumes the next two characters, so it must become_5F. Without this,snake_case_itemwould have been corrupted by the very fix meant to stop corruption.ReminderList (
Examples/ReminderList/ReminderList.swift)Pulled into scope.
generate_labelhand-rolled a second, weaker copy of this layout and never sanitized at all — so a reminder titledpay ^XZ rentemitted a second^XZ, terminating the label early and dropping every row below it. A live injection bug, worse than the one #53 describes.Rather than duplicate the fixes it now delegates to
ListLayout(itemIndent: 80)— the80preserves the historical left margin, and the derived^PW1200matches what it hardcoded. Drops ~30 lines of parallel geometry code.Added a
ReminderListTeststarget (mirroring the existingLabelPrintTestspattern); the example had no coverage before.Verification
Rendered through Labelary, the reference renderer, with
Costco: / café piña jalapeño / bad^XZ and ~JA ok / snake_case_item:^CI28working)^and~print as literal characters, label not truncated^CFdefault holds and the header font does not leakswift build && swift test— Build complete, 123 tests / 26 suites passed (110 / 25 onmain).Notes
docs/plans/anddocs/specs/still show the old^A0N/sanitizedsnippets. They are dated records of the completed examples reorg that correctly list Emit leaner, correcter ZPL: ^CF default font, ^CI28 UTF-8, ^FH escaping #53 as then-future work, so they were left as history.ListLayoutoutput.^FBfield blocks) will rework these same emission lines and should be sequenced after this.