@@ -621,10 +621,10 @@ replace needle@(Text _ _ neeLen)
621621 (Text repArr repOff repLen)
622622 haystack@(Text hayArr hayOff hayLen)
623623 | neeLen == 0 = emptyError "replace"
624− | len < 0 = overflowError "replace"
625− | len == 0 = empty
626624 | L.null ixs = haystack
627− | otherwise = Text (A.run x) 0 len
625+ | len > 0 = Text (A.run x) 0 len
626+ | len < 0 = overflowError "replace"
627+ | otherwise = empty
628628 where
629629 ixs = indices needle haystack
630630 len = hayLen - (neeLen - repLen) * L.length ixs