rightfold / purescript-bytestrings

Immutable packed byte sequences.
https://pursuit.purescript.org/packages/purescript-bytestrings
BSD 3-Clause "New" or "Revised" License
9 stars 8 forks source link

fromString should return Nothing for invalid input? #12

Open safareli opened 5 years ago

safareli commented 5 years ago

There was test quickCheck $ fromString "LOL" Hex === Nothing which was failing and now it's commented https://github.com/rightfold/purescript-bytestrings/blob/2d58bc68ac1d3650ee2a4f620057f526043f6352/test/Main.purs#L88-L89

we should either update type or fix the bug

safareli commented 5 years ago

it was introduced here https://github.com/rightfold/purescript-bytestrings/commit/532c8d369fc2c483171edee66140c1b15e3b77af#diff-f27773669f759a4a90a0d747ce24836bR224

probably Buffer.fromString is not throwing any more?

safareli commented 5 years ago

looks like Buffer.from is not throwing:

➜ node -v 
v8.12.0

➜  node
> Buffer.from("LOL", "utf8")
<Buffer 4c 4f 4c>
> Buffer.from("LOL", "hex")
<Buffer >
> Buffer.from("LOL#$%^&*(", "hex")
<Buffer >
> Buffer.byteLength("LOL#$%^&*(", "hex")
5
> Buffer.from("éééé", "ascii")
<Buffer e9 e9 e9 e9>
> Buffer.from("éééé", "ascii").toString()
'����'
> Buffer.from("éééé", "ascii").toString("ascii")
'iiii'
> Buffer.from("éééé", "ascii").toString("utf8")
'����'
> Buffer.byteLength("0x8", "hex")
1
> Buffer.from("0x8", "hex")
<Buffer >
> Buffer.from("qqq0x8123132", "hex")
<Buffer >
> Buffer.from("110x8123132", "hex")
<Buffer 11>
> Buffer.from("1_-10x8123132", "hex")
<Buffer >

and i'm not able to reproduce https://github.com/purescript-node/purescript-node-buffer/issues/23

so it seems we should remove Maybe wrapping

safareli commented 5 years ago

https://github.com/nodejs/node/issues/8569#issuecomment-316336196

safareli commented 5 years ago

https://github.com/nodejs/node/issues/24722