Skip to content

Commit

Permalink
Explicit null check
Browse files Browse the repository at this point in the history
  • Loading branch information
BraydenLangley committed Feb 27, 2025
1 parent c509da4 commit b87bd4b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/primitives/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ function utf8ToArray (str: string): number[] {
const result: number[] = []

for (let i = 0; i < str.length; i++) {
let codePoint = str.codePointAt(i)
const cp = str.codePointAt(i)
if (cp === undefined) {
// Should never be out of range.
throw new Error(`Index out of range: ${i}`)
}
let codePoint = cp

if (codePoint > 0xFFFF) {
// Valid surrogate pair => skip the next code unit because codePointAt
Expand Down

0 comments on commit b87bd4b

Please sign in to comment.