You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
onDataString is easy to use but is unfortunately a subtle foot-gun.
This function calls the underlying node API returning a buffer, and then calls Buffer.toString on the result.
But if a character would span two data events, each Buffer.toString will replace the initial/trailling code units with the replacement character.
As it stands, onDataString should be documented with a clear warning, it is not suitable for general purpose use but only streams that are either guaranteed to have single-byte encoded characters/known short lengths.
The comment on setEncoding unfortunately recommends this:
"Where possible, you should try to use onDataString instead of this function."
I think if this recommended onData, it might be more clear to the user that something fishy is going on.
The text was updated successfully, but these errors were encountered:
nwolverson
added a commit
to nwolverson/purescript-language-server
that referenced
this issue
Nov 26, 2021
A character that is multiple UTF-8 code units that got split across multiple 'data' events
was converted into replacement characters due to Buffer.toString being called on the chunks
individually. Instead collect all chunks and call toString after joining them.
purescript-node/purescript-node-streams#37
onDataString
is easy to use but is unfortunately a subtle foot-gun.This function calls the underlying node API returning a buffer, and then calls
Buffer.toString
on the result.But if a character would span two
data
events, eachBuffer.toString
will replace the initial/trailling code units with the replacement character.As it stands,
onDataString
should be documented with a clear warning, it is not suitable for general purpose use but only streams that are either guaranteed to have single-byte encoded characters/known short lengths.The comment on
setEncoding
unfortunately recommends this:I think if this recommended
onData
, it might be more clear to the user that something fishy is going on.The text was updated successfully, but these errors were encountered: