Skip to content

Commit ac24850

Browse files
author
Grégory Saive
authored
Merge pull request #180 from rg911/task/g175_add_insignificant_zeros
Issue #175 added contol char handler in convert.ts
2 parents 0f1928e + 4bc077a commit ac24850

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

src/core/format/Convert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class Convert {
168168
const rawString = Convert.rstr2utf8(input);
169169
let result = '';
170170
for (let i = 0; i < rawString.length; i++) {
171-
result += rawString.charCodeAt(i).toString(16);
171+
result += rawString.charCodeAt(i).toString(16).padStart(2, '0');
172172
}
173173
return result;
174174
}

src/core/format/Utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const split = (name, processor) => {
133133

134134
export const generateNamespaceId = (parentId, name) => {
135135
const hash = sha3_256.create();
136-
hash.update(Uint32Array.from(parentId).buffer);
136+
hash.update(Uint32Array.from(parentId).buffer as any);
137137
hash.update(name);
138138
const result = new Uint32Array(hash.arrayBuffer());
139139
// right zero-filling required to keep unsigned number representation

test/core/format/Convert.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ describe('convert', () => {
233233
// Assert:
234234
expect(actual).to.equal('e58588e7a7a6e585a9e6bca2');
235235
});
236+
237+
it('utf8 text to hex with control char', () => {
238+
// Act:
239+
const actual = convert.utf8ToHex(String.fromCodePoint(0x0f) + ' Hello World!');
240+
241+
// Assert:
242+
expect(actual).to.equal('0f2048656c6c6f20576f726c6421');
243+
});
236244
});
237245

238246
describe('signed <-> unsigned byte', () => {

test/core/format/IdGenerator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const mosaicTestVector = {
143143
describe('id generator', () => {
144144
function generateNamespaceId(parentId, name) {
145145
const hash = sha3_256.create();
146-
hash.update(Uint32Array.from(parentId).buffer);
146+
hash.update(Uint32Array.from(parentId).buffer as any);
147147
hash.update(name);
148148
const result = new Uint32Array(hash.arrayBuffer());
149149
// right zero-filling required to keep unsigned number representation

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"outDir": "dist",
1414
"allowJs": false,
1515
"lib": [
16-
"es2016",
16+
"es2017",
1717
"dom"
1818
],
1919
"typeRoots": [

0 commit comments

Comments
 (0)