Skip to content

Commit b792bce

Browse files
author
Baha
committed
fix: metadata value non-ascii utf8 encoding issue fixed
1 parent f9f12a6 commit b792bce

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/core/format/Convert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class Convert {
190190
* @return {Uint8Array}
191191
*/
192192
public static utf8ToUint8 = (input: string): Uint8Array => {
193-
const hex = Convert.utf8ToHex(Convert.rstr2utf8(input));
193+
const hex = Convert.utf8ToHex(input);
194194
return Convert.hexToUint8(hex);
195195
};
196196

test/core/format/Convert.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ describe('convert', () => {
407407
});
408408
});
409409

410-
describe('utf8ToUni8', () => {
410+
describe('utf8ToUint8', () => {
411411
it('should convert numeric string to Uint8Array', () => {
412412
const actual = '123456789';
413413
// Act:
@@ -428,6 +428,16 @@ describe('convert', () => {
428428
expect(uint.length).to.be.equal(actual.length);
429429
expect(convert.uint8ToHex(uint)).to.be.equal('74657374');
430430
});
431+
432+
it('should convert non-ascii utf8 string to Uint8Array', () => {
433+
const actual = '存在';
434+
// Act:
435+
const uint = convert.utf8ToUint8(actual);
436+
437+
// Assert:
438+
expect(uint.length).to.be.equal(6);
439+
expect(convert.uint8ToHex(uint)).to.be.equal('E5AD98E59CA8');
440+
});
431441
});
432442

433443
describe('uint8ToUtf8', () => {
@@ -450,6 +460,16 @@ describe('convert', () => {
450460
// Assert:
451461
expect(result).to.be.equal(expected);
452462
});
463+
464+
it('should convert Uint8Array to non-ascii utf8 string ', () => {
465+
const expected = '存在';
466+
const actual = convert.utf8ToUint8(expected);
467+
// Act:
468+
const result = convert.uint8ToUtf8(actual);
469+
470+
// Assert:
471+
expect(result).to.be.equal(expected);
472+
});
453473
});
454474

455475
describe('numberToUint8Array', () => {

0 commit comments

Comments
 (0)