Skip to content

Commit 4104207

Browse files
committed
Handle invarient inside unsafeTextWithLength
1 parent ae1d2a6 commit 4104207

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

prettyprinter/src/Prettyprinter/Internal.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ unsafeTextWithoutNewlines text = case T.uncons text of
491491
-- unsafeTextWithLength "😃" (realLength "😃")
492492
-- @
493493
unsafeTextWithLength :: Text -> Int -> Doc ann
494-
unsafeTextWithLength txt l = Text l txt
494+
unsafeTextWithLength txt l | T.null txt = Empty
495+
| l == 1 && T.length txt == 1 = Char (T.head txt) -- no wide character or control
496+
| otherwise = Text l txt
495497

496498
-- | The empty document behaves like @('pretty' "")@, so it has a height of 1.
497499
-- This may lead to surprising behaviour if we expect it to bear no weight

0 commit comments

Comments
 (0)