Repository navigation
fix(printer): thread arabicShaping flag through backend and frontend print paths - #452
Merged
Merged
Conversation
…nes (#437) ESC/POS encoders silently skipped every receipt line containing Persian/Arabic script unless the printer profile declared arabicShaping, and nothing exposed that flag — so merchants with Persian product names got bills with no items at all. Add a renderer-global 'printerArabicShaping' setting that threads through the same paths as the existing useUnicode option: - pos-settings store + Settings → Printing toggle (en/fa/es/pt) - frontend encoders: safePrinterText emits pure ASCII+Arabic lines when shaping is enabled; other non-ASCII scripts stay blocked - backend print-bill/print-kot accept an arabicShaping body field; an explicit boolean overrides the profile default, absence keeps it - warning toast now localized (printWarnings.* namespace) naming the new setting when Persian/Arabic lines were dropped Default stays off so generic printers never receive unshaped text.
…erText shaping path
… ESLint any-cast errors
Addresses greptile P1/P2 on #450: raw() shaping output now strips C0/DEL control bytes (preventing printer-command injection via labels) and reproduces encoder centering via an explicit column budget at centered call sites, so double-width Persian business names keep their heading padding.
…ed-line width bounds
The cancelled review pipeline left safePrinterText calling the optional align() method without optional chaining, so Next.js typecheck failed with TS2722 at warnings.ts:122 and :127 and broke both the Lint & Build and Playwright CI jobs. centerRawLine already guarantees align exists; optional chaining keeps runtime behavior identical.
Contributor
Greptile SummaryThe PR consistently carries the Arabic/Persian firmware-shaping preference through browser, API, receipt, tax-bill, KOT, and preview printing paths.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code failure remaining after reviewing the shaping, propagation, sanitization, and width-handling paths. Explicit boolean overrides are carried through the active print paths, profile defaults remain intact when no override is supplied, and shaped output is sanitized and bounded without altering established English output.
|
| Filename | Overview |
|---|---|
| frontend/src/lib/printer/warnings.ts | Adds shaping-safe line classification, control-byte sanitization, display-width bounding, and centralized raw-text centering without an established defect. |
| frontend/src/hooks/usePrinter.ts | Propagates the persisted shaping preference through local ESC/POS and backend receipt, tax-bill, and KOT paths. |
| main/routes/printers.ts | Accepts only explicit boolean shaping overrides and threads them through bill preview, receipt dispatch, and KOT dispatch. |
| main/printers/thermal.ts | Resolves request overrides against printer-profile defaults and applies sanitization and width limits to backend shaped output. |
| frontend/src/lib/printer/receipt-encoder.ts | Threads shaping behavior through classic, compact, and detailed receipt fields while supplying column budgets where needed. |
| frontend/src/lib/printer/kot-encoder.ts | Enables shaping for KOT metadata, items, add-ons, and instructions while retaining truncation and warning behavior. |
| tests/printer.test.ts | Adds broad regression coverage for shaping gates, control-byte removal, centering, width limits, propagation, and English byte identity. |
| tests/bills-print-api.test.ts | Verifies that the explicit backend override restores Persian item lines while omitted overrides preserve prior behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Printer settings toggle] --> B[POS settings store]
B --> C[Receipt and tax-bill printing]
B --> D[KOT printing]
B --> E[Receipt preview]
C --> F{Print transport}
D --> F
F -->|Frontend ESC/POS| G[safePrinterText]
F -->|Backend printer API| H[Route boolean override]
E --> H
H --> I[prepareReceipt / printReceipt / printKOT]
I --> J[Profile default unless explicitly overridden]
J --> K[buildEscPos]
G --> L[Sanitize, bound, and emit shaped text]
K --> L
Reviews (1): Last reviewed commit: "fix(printer): satisfy strict null check ..." | Re-trigger Greptile
This was referenced Aug 22, 2026
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.
Intent
Finish PR #450 (fix for issue #437 'Not showing Items in Bill': receipt item lines silently disappear from desktop ESC/POS receipts when the global Arabic/Persian shaping support printer setting is enabled) and drive it to merge-ready. The PR threads the arabicShaping flag consistently through backend and frontend print paths, preserves warning reasons in warnings-toast classification, allows Persian formatting characters in shaping guards, sanitizes C0/DEL control bytes from raw shaped output, bounds shaped lines to printer width, and reproduces encoder centering centrally inside safePrinterText. All open review comments (greptile P1 centered-alignment and P2 control-byte security findings on frontend/src/lib/printer/warnings.ts) are addressed by commits already on the branch head. CAPTAIN'S STANDING RULING (feed exactly this to any gate asking about centering): keep the shared helper behavior - safePrinterText's centralized centering is authoritative; do NOT restructure call sites to use encoder centerCols instead. The new fix commit on fm/fm-flocafe-450-fixes repairs a TS2722 strict-null-check break (alignableEnc.align called without optional chaining at warnings.ts:122/127) left behind by a cancelled review-pipeline run; that typecheck failure broke both the 'Lint & Build Validation (Linux)' and 'End-to-End Playwright Tests' CI jobs on the latest branch push. Constraint: English-only receipt output must remain byte-identical.
What Changed
printerArabicShapingtoggle to the POS settings store, settings UI, and i18n (en/es/fa/pt) so merchants can opt in to sending raw Arabic/Persian text to firmware-capable printersarabicShapingoverride from frontend renderer requests (usePrinter,orders/page.tsx) through the backend Express routes (print-bill,print-kot) intoprintReceipt,printKOT,prepareReceipt, andbuildEscPos, where the profile's default is only overridden when an explicit boolean arrives from the request bodysafePrinterTextinwarnings.tsto pass Arabic-only lines through the unsupported-character guard when shaping is enabled, sanitizing C0/DEL control bytes, bounding shaped output to printer column width, and reproducing encoder centering via raw bytes; localized the warnings toast with shaping-aware hintstruncateShapedLinehelpers and column-aware truncation inbuildEscPosand receipt templates so shaped lines never exceed printer width, and allowed Persian formatting characters (RLM, ZWNJ, ZWJ, ellipsis) in the shaping guard regexRisk Assessment
✅ Low: Change is well-bounded: threads a single boolean flag through existing print paths with correct guard logic at each boundary, preserves ASCII byte-identical output, and comprehensive tests cover all material code paths.
Testing
Verified PR #450 end-to-end: both TypeScript checks pass, all 411 targeted printer and print-API tests pass (360 printer + 28 bills-print-api + 8 receipt-printing + 4 receipt-column-width + 3 printer-width-refresh + 8 printer-migrations), English byte-identical receipt output is confirmed by the existing regression test, and the TS2722 strict-null-check fix on optional align chaining is in place and typechecks cleanly.
Evidence: Printer tests full output (360/360 passed)
Evidence: Bills print API tests (28/28 passed)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npx tsccd frontend && npx tsc --noEmit -p tsconfig.jsonnpx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.ts(360/360 passed)npx ts-node --transpile-only -P tests/tsconfig.json tests/bills-print-api.test.ts(28/28 passed)npx ts-node --transpile-only -P tests/tsconfig.json tests/receipt-printing.test.ts(8/8 passed)npx ts-node --transpile-only -P tests/tsconfig.json tests/receipt-column-width.test.ts(4/4 passed)node tests/run-electron-node-test.cjs tests/printer-width-refresh.test.ts(3/3 passed)node tests/run-electron-node-test.cjs tests/printer-usb-device-path-migration.test.ts(8/8 passed)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Fixes #437
Refs #438