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

RangeError: Invalid code point #358

Closed
Streeterxs opened this issue Oct 22, 2021 · 2 comments · Fixed by #374
Closed

RangeError: Invalid code point #358

Streeterxs opened this issue Oct 22, 2021 · 2 comments · Fixed by #374

Comments

@Streeterxs
Copy link

Streeterxs commented Oct 22, 2021

I'm trying to validate a input in a test file to find if the given string is a GlobalID but fromGlobalId is throwing error for string: 'E23114447202105201514Zt2MM4ipJef'.

The error is:

    RangeError: Invalid code point 1405880
        at Function.fromCodePoint (<anonymous>)

      83 |     // Check if it's a valid globalId, if so, replace it with a static value
      84 |     console.log({value});
    > 85 |     const result = fromGlobalId('E23114447202105201514Zt2MM4ipJef');

I logged utf8ArrayToString function

Just before last String.fromCodePoint:

    const d = input[i++];
    console.log({
      input,
      a,
      b,
      c,
      d,
      value: ((a & 0x07) << 18) | ((b & 0x3f) << 12) | ((c & 0x3f) << 6) | (d & 0x3f)})
    result += String.fromCodePoint(
      ((a & 0x07) << 18) | ((b & 0x3f) << 12) | ((c & 0x3f) << 6) | (d & 0x3f),
    );

result:

  console.log
    {
      input: [
         19, 109, 245, 215, 142,  56,
        239, 109,  54, 215,  78, 118,
        211,  94, 117, 225, 155, 118,
         48, 206,  34, 164, 151, 159
      ],
      a: 245,
      ae: 7,
      b: 215,
      c: 142,
      d: 56,
      value: 1405880
    }
@IvanGoncharov
Copy link
Member

@Streeterxs Can you provide a little bit more context?
It looks like your string contains invalid UTF-8 bytes since 1405880 is not a valid codepoint:
https://unicode.scarfboy.com/?s=1405880
Can you please provide the expected behavior for this string?

@sibelius
Copy link
Contributor

we use this method to validate if a given id is a valid globalId

this used to work, however right now we need to wrap it in a try catch

IvanGoncharov added a commit to IvanGoncharov/graphql-relay-js that referenced this issue Dec 17, 2021
Fixes graphql#358
Note: it's temprorary workaround until we design a better API
IvanGoncharov added a commit to IvanGoncharov/graphql-relay-js that referenced this issue Dec 17, 2021
Fixes graphql#358
Note: it's temprorary workaround until we design a better API
IvanGoncharov added a commit to IvanGoncharov/graphql-relay-js that referenced this issue Dec 19, 2021
Fixes graphql#358
Note: it's temprorary workaround until we design a better API
IvanGoncharov added a commit that referenced this issue Dec 19, 2021
Fixes #358
Note: it's temporary workaround until we design a better API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants