Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ function base (ALPHABET) {
const b256 = new Uint8Array(size)
// Process the characters.
while (psz < source.length) {
// Find code of next character
const charCode = source.charCodeAt(psz)
// Base map can not be indexed using char code
if (charCode > 255) { return }
// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]
let carry = BASE_MAP[charCode]
// Invalid character
if (carry === 255) { return }
let i = 0
Expand Down
6 changes: 5 additions & 1 deletion src/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ function base (ALPHABET) {
const b256 = new Uint8Array(size)
// Process the characters.
while (psz < source.length) {
// Find code of next character
const charCode = source.charCodeAt(psz)
// Base map can not be indexed using char code
if (charCode > 255) { return }
// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]
let carry = BASE_MAP[charCode]
// Invalid character
if (carry === 255) { return }
let i = 0
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@
"alphabet": "0123456789fabcdef",
"description": "poorly formed alphabet",
"exception": "^TypeError: f is ambiguous$"
},
{
"alphabet": "base58",
"description": "character whose code exceeds the highest index of base map (>=256)",
"exception": "^Error: Non-base58 character$",
"string": "\u1000"
}
]
}
8 changes: 7 additions & 1 deletion ts_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ function base (ALPHABET: string): base.BaseConverter {

// Process the characters.
while (psz < source.length) {
// Find code of next character
const charCode = source.charCodeAt(psz)

// Base map can not be indexed using char code
if (charCode > 255) return

// Decode character
let carry = BASE_MAP[source.charCodeAt(psz)]
let carry = BASE_MAP[charCode]

// Invalid character
if (carry === 255) return
Expand Down