Back to feed
Dev.to
Dev.to
7/3/2026
a width check said the string was safe to cut. it split a kanji in half.

a width check said the string was safe to cut. it split a kanji in half.

Short summary

A bug in cli-table3's string truncation code split Unicode surrogate pairs (rare CJK characters outside the BMP, like kanji U+20BB7) in half when fitting text to table columns. The fast-path optimization incorrectly assumed that matching UTF-16 code-unit length to display width meant all characters were simple, but surrogate-pair wide characters triggered this false positive. The fix adds a surrogate check and uses Array.from() for proper code-point iteration.

  • cli-table3 truncated surrogate-pair wide characters by slicing between code units instead of splitting after whole characters
  • Root cause: an optimization assumed length === displayWidth meant no complex characters, but surrogate pairs (2 units, 2 columns) matched while needing special handling
  • Fix: guard the fast path with surrogate detection and iterate by code point with Array.from() instead of slicing by index

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more