Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromCharCode BMP #153

Closed
jamesdbrock opened this issue Sep 22, 2021 · 5 comments · Fixed by #163
Closed

fromCharCode BMP #153

jamesdbrock opened this issue Sep 22, 2021 · 5 comments · Fixed by #163
Labels
type: bug Something that should function correctly isn't.

Comments

@jamesdbrock
Copy link

fromCharCode should return Nothing if the code is out of the Basic Multilingual Plane Char range, right?

fromCharCode = toEnum

>>> show $ fromCharCode 65900

(Just 'Ŭ')

The Bounded instance for Char says that “Characters fall within the Unicode range,” but the Char says “guaranteed to contain one code unit.”

@MonoidMusician
Copy link
Contributor

Oh interesting, it appears this is actually the line at fault:
https://github.com/purescript/purescript-enums/blob/170d959644eb99e0025f4ab2e38f5f132fd85fa4/src/Data/Enum.purs#L316-L318

It's using top and bottom for ints, not chars. I guess n >= toCharCode bottom && n <= toCharCode top might work?

String.fromCharCode just does (code) % 0x10000 on the code, so what you're seeing is 65900 % 0x10000 = 0x16C.

@JordanMartinez
Copy link
Contributor

I've opened an issue in purescript-enum to track this. Should this issue be closed?

@thomashoneyman
Copy link
Member

I think it’s reasonable it stays open until the upstream issue is addressed

@JordanMartinez JordanMartinez added the type: bug Something that should function correctly isn't. label Dec 1, 2021
@JordanMartinez
Copy link
Contributor

Technically, we still need a release of that library and then a dependency update here.

@JordanMartinez
Copy link
Contributor

PR ready for approval: #163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something that should function correctly isn't.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants