purescript/purescript-strings

Bug in Data.String.Unsafe.char

stkb opened this issue ยท 4 comments

stkb commented

The js code for Data.String.Unsafe.char looks like this:

exports.char = function (s) {
  if (s.length !== 1) return s.charAt(0);
  throw new Error("Data.String.Unsafe.char: Expected string of length 1.");
};

I'm pretty sure that line on line 21 that !== is meant to be an ===; atm the function's bugging out for good inputs & vice versa. Should be:

if (s.length === 1) return s.charAt(0);
stkb commented

Have just glanced at the charCodeAt function in the same file and it looks like the if-condition in that function should be reversed too.

๐Ÿ‘ Yep, let's change it.

๐Ÿ™ˆ

Thanks for the report!

stkb commented

๐Ÿ‘ thanks