Skip to content

Commit

Permalink
fix: protect against bundling bugs (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Jul 21, 2023
1 parent d01fa13 commit 2455e04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/uuidv7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@ export class UUID {
toString(): string {
let text = ''
for (let i = 0; i < this.bytes.length; i++) {
text += DIGITS.charAt(this.bytes[i] >>> 4)
text += DIGITS.charAt(this.bytes[i] & 0xf)
text = text + DIGITS.charAt(this.bytes[i] >>> 4) + DIGITS.charAt(this.bytes[i] & 0xf)
if (i === 3 || i === 5 || i === 7 || i === 9) {
text += '-'
}
}

if (text.length !== 36) {
// We saw one customer whose bundling code was mangling the UUID generation
// rather than accept a bad UUID, we throw an error here.
throw new Error('Invalid UUIDv7 was generated')
}
return text
}

Expand Down
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4735,15 +4735,10 @@ camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001400:
version "1.0.30001421"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001421.tgz#979993aaacff5ab72a8d0d58c28ddbcb7b4deba6"
integrity sha512-Sw4eLbgUJAEhjLs1Fa+mk45sidp1wRn5y6GtDpHGBaNJ9OCDJaVh2tIaWWUnGfuXfKf1JCBaIarak3FkVAvEeA==

caniuse-lite@^1.0.30001473, caniuse-lite@^1.0.30001489:
version "1.0.30001492"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001492.tgz#4a06861788a52b4c81fd3344573b68cc87fe062b"
integrity sha512-2efF8SAZwgAX1FJr87KWhvuJxnGJKOnctQa8xLOskAXNXq8oiuqgl6u1kk3fFpsp3GgvzlRjiK1sl63hNtFADw==
caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001473, caniuse-lite@^1.0.30001489:
version "1.0.30001517"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001517.tgz"
integrity sha512-Vdhm5S11DaFVLlyiKu4hiUTkpZu+y1KA/rZZqVQfOD5YdDT/eQKlkt7NaE0WGOFgX32diqt9MiP9CAiFeRklaA==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 2455e04

Please sign in to comment.