Skip to content

Commit 1da0769

Browse files
committed
fix: start should less then end for encodeChunk()
1 parent 4ebd47f commit 1da0769

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/lib/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const ErrorMsg = {
1818
fromArrayBufferInvalidParam: 'Invalid input, should be ArrayBuffer or Uint8Array',
1919
notString: 'Invalid value of parameter, should be string',
2020
notValidB64String: 'Valid base64 string only contains /^[a-zA-Z0-9+/_-]+={0,2}$/',
21-
startMustGrossOrEqualToEnd: 'Parameters of start should less then end',
21+
startMustGrossOrEqualToEnd: 'Parameters of start should less then or equal to end',
22+
startMustGrossToEnd: 'Parameters of start should less then end',
2223
textEncoderUndefined: 'TextEncoder undefined!',
2324
textDecoderUndefined: 'TextDecoder undefined!',
2425
}

src/lib/from_buffer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function fromUint8Array(input: Uint8Array): string {
3939

4040

4141
function encodeChunk(input: Uint8Array, start: number, end: number): string {
42-
if (start > end) {
43-
throw new Error(ErrorMsg.startMustGrossOrEqualToEnd)
42+
if (start >= end) {
43+
throw new Error(ErrorMsg.startMustGrossToEnd)
4444
}
4545
const arrLen = Math.ceil((end - start) / 3)
4646
const ret: string[] = new Array(arrLen)

test/20_from_buffer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ describe(filename, () => {
3333
const fn = <(input: Uint8Array, start: number, end: number) => string> mods.__get__(fnName)
3434

3535
it('with invalid start/end value', () => {
36-
[ [1, 0], [0, -1] ].forEach(([start, end]) => {
36+
[ [1, 0], [0, -1], [1, 1], [0, 0] ].forEach(([start, end]) => {
3737
try {
3838
fn(inputUint8Array[0], start, end)
3939
assert(false, 'Should throw error, but NOT')
4040
}
4141
catch (ex) {
4242
assert(
43-
ex.message && ex.message.includes(ErrorMsg.startMustGrossOrEqualToEnd),
43+
ex.message && ex.message.includes(ErrorMsg.startMustGrossToEnd),
4444
ex.message,
4545
)
4646
}

0 commit comments

Comments
 (0)