Skip to content

Commit 06b0cb7

Browse files
committed
chore: minor hardening
1 parent 47a7791 commit 06b0cb7

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const makeMessage = (name, extra) => `Expected${name ? ` ${name} to be` : ''} an
88
const TypedArray = Object.getPrototypeOf(Uint8Array)
99

1010
export function assertTypedArray(arr) {
11-
if (arr instanceof TypedArray) return
11+
if (arr && arr instanceof TypedArray) return
1212
throw new TypeError('Expected a TypedArray instance')
1313
}
1414

base64.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export function fromBase64url(str, options) {
7474

7575
// By default accepts both padded and non-padded variants, base64 or base64url
7676
export function fromBase64any(str, { format = 'uint8', padding = 'both', ...rest } = {}) {
77+
if (typeof str !== 'string') throw new TypeError(E_STRING)
7778
const isBase64url = !str.includes('+') && !str.includes('/') // likely to fail fast, as most input is non-url, also double scan is faster than regex
7879
return fromBase64common(str, isBase64url, padding, format, rest)
7980
}

fallback/_utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export function assert(condition, msg) {
77
}
88

99
export function assertU8(arg) {
10-
if (!(arg instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
10+
if (arg && arg instanceof Uint8Array) return
11+
throw new TypeError('Expected an Uint8Array')
1112
}
1213

1314
// On arrays in heap (<= 64) it's cheaper to copy into a pooled buffer than lazy-create the ArrayBuffer storage

0 commit comments

Comments
 (0)