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

SyntaxError: Invalid or unexpected token at bufToBigInt on UC Browser only #39

Open
baptisteArno opened this issue Feb 25, 2023 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@baptisteArno
Copy link

baptisteArno commented Feb 25, 2023

My users have this error when using UC browser:

SyntaxError: Invalid or unexpected token
  at bufToBigInt(../../node_modules/.pnpm/@[email protected]/node_modules/@paralleldrive/cuid2/src/index.js:23:1)

CleanShot 2023-02-25 at 19 09 06@2x

For now, I don't have much more info because I don't have the right device to debug this. But I'll continue to investigate.

@ericelliott
Copy link
Collaborator

ericelliott commented Feb 27, 2023

Probably an old browser that doesn't support BigInt literals. You can probably compile them away in your build step. What compiler are you using?

@ericelliott
Copy link
Collaborator

Actually, it looks like it may support BigInt literals (otherwise, it should have stopped on line 21), but maybe there's a bug where it fails to look ahead to see that 0n is a BigInt literal, and not a hex literal (which is denoted with a leading 0x)? Can you try replacing that line with BigInt(0) and see if that solves the error?

@ericelliott ericelliott added the help wanted Extra attention is needed label Feb 27, 2023
@baptisteArno
Copy link
Author

I decided to remove it from the bundle, indeed! So I can't really do more testing!

Thank you very much for the help. 🙏

@ericelliott
Copy link
Collaborator

I think we still probably need to get this fixed. Thanks for reporting!

@luizlopescom
Copy link

I received the same error. Since the buf is a string within 0-9 and a-f, I converted it into an array splitting each 2 characters. I really don't know if it is secure. So I am sharing my code:

function bufToBigInt(buf) {

  //Convert buf to Uint8Array
  const length = buf.length / 2;
  const uint8Array = new Uint8Array(length);
  for (let i = 0; i < length; i++) {
  	uint8Array[i] = parseInt(buf.substr(i * 2, 2), 16);
  }
  let bits = 8n;
  let value = 0n;
  //for (const i of buf.values()) {
  for (const i of uint8Array) {
    const bi = BigInt(i);
    value = (value << bits) + bi;
  }
  return value;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants