on master help sign in
Fix an issue where multibyte characters resulted in an incorrect buffer length in encodeUtf8
commit90d36ec1a0be48c25ffc15ddf66c83971e519f34 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSat 10 Dec 2016, 21:21 (10 years ago) parent503c396
1 file changed+2−2
Data/Text/Encoding.hs+2−2
Data/Text/Encoding.hs+2−2
@@ -406,7 +406,8 @@ encodeUtf8 (Text arr off len)
406406 memcpy ptr' ptr (fromIntegral utf8len)
407407 return (PS fp' 0 utf8len)
408408#else
409−encodeUtf8 (Text txt) = toByteString 0 (Just (js_length txt)) $ js_encodeUtf8 txt
409+encodeUtf8 (Text txt) = toByteString 0 (Just (byteLength buf - 1)) buf
410+ where buf = js_encodeUtf8 txt
410411#endif
411412
412413-- | Decode text from little endian UTF-16 encoding.
@@ -503,5 +504,4 @@ foreign import ccall unsafe "_hs_text_encode_utf8" c_encode_utf8
503504#else
504505foreign import javascript unsafe "h$textFromString" js_fromString :: JSString -> (# ByteArray#, Int# #)
505506foreign import javascript unsafe "h$encodeUtf8($1)" js_encodeUtf8 :: JSString -> Buffer
506−foreign import javascript unsafe "$1['length']" js_length :: JSString -> Int
507507#endif