Repository navigation
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
Greptile SummaryThe PR consistently threads the Arabic/Persian shaping preference through frontend and backend print paths and adds regression coverage for shaped receipt output. The follow-up changes also sanitize control characters and preserve centered alignment when shaped text is emitted as raw UTF-8.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| frontend/src/lib/printer/warnings.ts | Safely emits eligible shaped text as UTF-8 while stripping printer controls and explicitly accounting for centered alignment. |
| frontend/src/lib/printer/receipt-encoder.ts | Threads the shaping preference through receipt templates and supplies the appropriate centering widths for shaped store names. |
| frontend/src/lib/printer/kot-encoder.ts | Threads Arabic/Persian shaping through frontend kitchen-ticket text encoding. |
| frontend/src/lib/printer/tax-bill-encoder.ts | Applies shaping support to tax-bill output, including centered business-name rendering. |
| frontend/src/hooks/usePrinter.ts | Propagates the persisted shaping preference through hardware and local frontend print paths. |
| main/printers/thermal.ts | Applies explicit shaping overrides and allows supported Persian formatting characters in backend ESC/POS generation. |
| main/routes/printers.ts | Accepts boolean shaping overrides on bill and KOT print requests and passes them to thermal printing. |
| tests/printer.test.ts | Adds regression coverage for shaped UTF-8 output, formatting controls, mixed-script rejection, sanitization, and alignment. |
| tests/bills-print-api.test.ts | Verifies that request-level shaping configuration overrides the printer profile during receipt preparation. |
Reviews (2): Last reviewed commit: "no-mistakes(document): Documented Arabic..." | Re-trigger Greptile
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
|
This work continues in #452, which carries the same fix plus all review fixes (control-byte sanitization, shaped-line width bounds, centralized centering preserved inside safePrinterText, mixed-script warning classification, ASCII byte stability) and a strict-typecheck build repair for the TS2722 failure that broke the last CI runs on this branch. Checks are green there (12 passed / 0 failed / 1 skipped), so closing this PR as superseded. |
…print paths (#452) * fix(printers): global Arabic/Persian shaping setting restores item lines (#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. * no-mistakes(review): Preserve Persian ESC/POS items with Unicode currency * no-mistakes(review): Allow Persian formatting controls in printer shaping guards * no-mistakes(review): Fix frontend shaping propagation, previews, and warning reasons * no-mistakes(review): Allow Persian RLM and ellipsis in shaping guards * no-mistakes(test): Use enc.raw() for Persian UTF-8 bytes in safePrinterText shaping path * no-mistakes(document): Fixed API docs missing arabicShaping param and ESLint any-cast errors * fix(printers): sanitize controls and center shaped Persian lines 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. * no-mistakes(review): Fixed printer control-byte sanitization and shaped-line width bounds * no-mistakes(review): Disabled duplicate centering around shaped raw printer segments * no-mistakes(review): Bound KOT add-on truncation to printer width * no-mistakes(review): Bound shaped backend printer lines to column widths * no-mistakes(review): Preserve ASCII bytes and classify mixed Arabic warnings * no-mistakes(document): Documented Arabic/Persian printer shaping support * fix(printer): satisfy strict null check on shaped centering align calls 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.
Intent
Fix issue #437: receipt item lines silently disappear from desktop ESC/POS receipts when the global 'Arabic/Persian shaping support' printer setting is enabled. Threads the arabicShaping flag consistently through backend and frontend print paths, includes shaping in Orders download-preview requests, preserves warning reasons in warnings-toast classification, allows Persian formatting characters in shaping guards. Follow-up commit 67ab89c addresses two greptile review comments on PR #450: strip C0/DEL control bytes from raw() shaping output and reproduce encoder centering via centerCols at centered call sites. User instructed resolving greptile comments before merge; English receipts stay byte-identical.
What Changed
Risk Assessment
✅ Low: No source-verifiable defects were found; shaping is gated, shaped output is sanitized and width-bounded, and ASCII-only output remains unchanged.
Testing
The focused suites and real preview route demonstrate Persian item preservation, shaping warnings, control-byte sanitization, centering, width limits, KOT coverage, and English byte identity; no full suite, lint, formatter, or static analysis was run, and a visual Orders-page screenshot was unavailable because no browser connection existed.
Evidence: Print preview E2E evidence
Rendered route-level preview showing Persian lines omitted with shaping disabled and emitted witharabicShaping: true.Evidence: Printer test transcript
Focused printer transcript with rendered receipt output and shaping/control-byte/centering checks.Evidence: Bill print API transcript
Source: Bill print API transcript (local file:
/Users/gurkiratkhaira/.no-mistakes/evidence/01M0KADV9T5AMPSAXYEF3G2J0Z/bills-print-api-transcript.txt)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed (5) ✅
frontend/src/lib/printer/receipt-encoder.ts:266- The intent requires “reproduce encoder centering via centerCols at centered call sites,” but the classic encoder keeps alignment centered after line 259 and the changed Persian-capable calls at lines 266 and 270 omit centerCols. With shaping enabled, safePrinterText uses raw(), so table/customer lines become left-aligned instead of preserving the existing centered output. Pass the appropriate centerCols value or confirm the intentional alignment change.main/printers/thermal.ts:1697- The backend shaping guard treats C0/DEL bytes as acceptable ASCII, so a Persian item such asچای\u001b p...passes arabicOnly and is emitted by Buffer.from at line 1742. The desktop print route therefore still allows embedded ESC/POS control commands when shaping is enabled, despite the follow-up sanitizing the frontend raw() path. Sanitize or reject C0/DEL bytes at buildEscPos before emission so receipts, plugins, and KOTs share the boundary.frontend/src/lib/printer/warnings.ts:103- raw() is called without a layout length, so it bypasses the encoder's wrapping. Several newly shape-enabled fields remain unbounded, such asTable: ${order.table.name}and the classic customer name; a long Persian value is emitted as an over-width physical line without warning, whereas the same path with shaping disabled goes through enc.text() and wraps. Preserve the encoder's width contract by wrapping or bounding shape-safe values at the shared helper/call sites.🔧 Fix: Fixed printer control-byte sanitization and shaped-line width bounds
1 error still open:
frontend/src/lib/printer/warnings.ts:121-safePrinterTextmanually adds centering spaces, then callsraw()without a layout length. ReceiptPrinterEncoder v3 treats the raw segment as zero-width and adds another half-line of centering on flush, so shaped centered headers and footer lines can overflow or appear far right. Pass the raw display width or disable the second centering at this shared boundary; see alignment behavior.🔧 Fix: Disabled duplicate centering around shaped raw printer segments
1 warning still open:
frontend/src/lib/printer/kot-encoder.ts:94- For a long add-on name,truncate(addonText, cols - 4)can producecols - 4characters, and the five-character+prefix makes the linecols + 1columns wide. With Arabic shaping enabled,safePrinterTextsends this line throughraw()without amaxColsbound, so the KOT can emit an over-width physical line instead of the wrapping used when shaping is disabled. Usecols - 5or pass an explicitmaxCols: colsbound.🔧 Fix: Bound KOT add-on truncation to printer width
1 warning still open:
main/printers/thermal.ts:1697- WhenarabicShapingis enabled, the newarabicOnlybranch at line 1697 emits unbounded backend lines. For example, a 32-column KOT with a Persian product name longer than 32 columns reachesformatKOTline 1554 and is written in full at line 1744, producing an over-width ticket without warning; compact receipts similarly leave long Persian store/customer/table fields unbounded. Bound or wrap these shaped fields before emission, matching the frontend width contract.🔧 Fix: Bound shaped backend printer lines to column widths
2 issues (1 error, 1 warning) still open:
main/printers/thermal.ts:1691- The intent requires “English receipts stay byte-identical,” but line 1691 removes every C0/DEL byte from every backend line before the Arabic-shaping branch. An ASCII note such asNo onions\nNo garlicis changed even with shaping disabled. Restrict sanitization to shaped output while preserving non-shaped ASCII bytes.frontend/src/lib/printer/warnings-toast.ts:43- Arabic warnings containing another unsupported character, such asکافه Café, are classified as generic becauseisArabicShapingSafeLinereturns false, despite the warning reason identifying Persian/Arabic text. Classify usinghasArabicScriptor the warning reason so the shaping/browser remedy remains visible.🔧 Fix: Preserve ASCII bytes and classify mixed Arabic warnings
✅ Re-checked - no issues remain.
npm run test:printernpm run test:bills-print-apiTemporary-database supertest check ofPOST /api/printers/print-billwithpreview: trueandarabicShaping: false/trueCaptured rendered ESC/POS receipt previews and warning payloadsAttempted read-only browser discovery; no browser connections were availablegit status --short --untracked-files=all✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.