Skip to content

Commit 6c54632

Browse files
committed
Fix alphabets with space in them
1 parent 69c09ed commit 6c54632

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

src/index.js

-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ function base (ALPHABET) {
6666
if (typeof source !== 'string') { throw new TypeError('Expected String') }
6767
if (source.length === 0) { return _Buffer.alloc(0) }
6868
var psz = 0
69-
// Skip leading spaces.
70-
if (source[psz] === ' ') { return }
7169
// Skip and count leading '1's.
7270
var zeroes = 0
7371
var length = 0
@@ -94,8 +92,6 @@ function base (ALPHABET) {
9492
length = i
9593
psz++
9694
}
97-
// Skip trailing spaces.
98-
if (source[psz] === ' ') { return }
9995
// Skip leading zeroes in b256.
10096
var it4 = size - length
10197
while (it4 !== size && b256[it4] === 0) {

test/fixtures.json

+68-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"alphabets": {
33
"base2": "01",
44
"base16": "0123456789abcdef",
5+
"base45": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",
56
"base58": "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
67
},
78
"valid": [
@@ -545,6 +546,71 @@
545546
"alphabet": "base58",
546547
"hex": "6d691bdd736346aa5a0a95b373b2ab",
547548
"string": "44Y6qTgSvRMkdqpQ5ufkN"
549+
},
550+
{
551+
"alphabet": "base45",
552+
"hex": "d71c91867aa08cc96b361f29",
553+
"string": "5AKG9ZNTTK/JJP2/$D"
554+
},
555+
{
556+
"alphabet": "base45",
557+
"hex": "e70558f0d75915b457b3e356",
558+
"string": "5R%/+F5SZ6LLW+J60D"
559+
},
560+
{
561+
"alphabet": "base45",
562+
"hex": "821b8ac934dca0a7627683b7",
563+
"string": "37ILC1NGCLFRNPB2QK"
564+
},
565+
{
566+
"alphabet": "base45",
567+
"hex": "925e5d9120eb85e3f47de98c",
568+
"string": "3P9IPF01 DWZ5TA/$W"
569+
},
570+
{
571+
"alphabet": "base45",
572+
"hex": "55543281883fa0e4b67ebfb4",
573+
"string": "23H+2M%XIGQ32UJ/YO"
574+
},
575+
{
576+
"alphabet": "base45",
577+
"hex": "d419c3781964d6873931178c",
578+
"string": "5772LW:CX0%LBPD.OZ"
579+
},
580+
{
581+
"alphabet": "base45",
582+
"hex": "c6d10718e79b1171fb71af6f",
583+
"string": "4$RXK2XNP WOWGL0 E"
584+
},
585+
{
586+
"alphabet": "base45",
587+
"hex": "f67db5bed2d32445f7da2c44",
588+
"string": "5:Z/BRXGU-0NV3G3TU"
589+
},
590+
{
591+
"alphabet": "base45",
592+
"hex": "7496e6d6346165fd2deb88ec",
593+
"string": "2$RSPPBNCP5-RE3S*K"
594+
},
595+
{
596+
"alphabet": "base45",
597+
"hex": "df10b11c5f90c825285c72f9",
598+
"string": "5J75BHERI1$04F/LS5"
599+
},
600+
{
601+
"alphabet": "base45",
602+
"hex": "2174a83619bb46aacca7beec",
603+
"string": " R%/+F5SZ6LLW+J60"
604+
},
605+
{
606+
"alphabet": "base45",
607+
"hex": "05e9b0213ba6e5e9fc62aa2906",
608+
"string": " /+F5SZ6LLW+ "
609+
},
610+
{
611+
"alphabet": "base45",
612+
"hex": "7496e6d6346165fd2debc7bd",
613+
"string": "2$RSPPBNCP5-RE3 "
548614
}
549615
],
550616
"invalid": [
@@ -574,13 +640,13 @@
574640
},
575641
{
576642
"alphabet": "base58",
577-
"description": "leading whitespace",
643+
"description": "leading whitespace is not base58 character",
578644
"exception": "^Error: Non-base58 character$",
579645
"string": " 1111111111"
580646
},
581647
{
582648
"alphabet": "base58",
583-
"description": "trailing whitespace",
649+
"description": "trailing whitespace is not base58 character",
584650
"exception": "^Error: Non-base58 character$",
585651
"string": "1111111111 "
586652
},

ts_src/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ function base (ALPHABET: string): base.BaseConverter {
8484

8585
let psz = 0
8686

87-
// Skip leading spaces.
88-
if (source[psz] === ' ') return
89-
9087
// Skip and count leading '1's.
9188
let zeroes = 0
9289
let length = 0
@@ -119,9 +116,6 @@ function base (ALPHABET: string): base.BaseConverter {
119116
psz++
120117
}
121118

122-
// Skip trailing spaces.
123-
if (source[psz] === ' ') return
124-
125119
// Skip leading zeroes in b256.
126120
let it4 = size - length
127121
while (it4 !== size && b256[it4] === 0) {

0 commit comments

Comments
 (0)