From 0d478a7f198fec2ed5fceada77c9819ebab96a81 Mon Sep 17 00:00:00 2001 From: James Ebert Date: Wed, 9 Feb 2022 07:14:47 -0700 Subject: [PATCH] fix: leading zeros in credential value encoding (#632) Signed-off-by: James Ebert --- packages/core/src/modules/credentials/CredentialUtils.ts | 2 +- .../src/modules/credentials/__tests__/CredentialUtils.test.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/modules/credentials/CredentialUtils.ts b/packages/core/src/modules/credentials/CredentialUtils.ts index 52bdb6ccc2..43b4b5653b 100644 --- a/packages/core/src/modules/credentials/CredentialUtils.ts +++ b/packages/core/src/modules/credentials/CredentialUtils.ts @@ -153,7 +153,7 @@ export class CredentialUtils { // If value is an int32 number string return as number string if (isString(value) && !isEmpty(value) && !isNaN(Number(value)) && this.isInt32(Number(value))) { - return value + return Number(value).toString() } if (isNumber(value)) { diff --git a/packages/core/src/modules/credentials/__tests__/CredentialUtils.test.ts b/packages/core/src/modules/credentials/__tests__/CredentialUtils.test.ts index 9684e1832a..6a391014f5 100644 --- a/packages/core/src/modules/credentials/__tests__/CredentialUtils.test.ts +++ b/packages/core/src/modules/credentials/__tests__/CredentialUtils.test.ts @@ -74,6 +74,10 @@ const testEncodings: { [key: string]: { raw: string | number | boolean | null; e raw: '0.1', encoded: '9382477430624249591204401974786823110077201914483282671737639310288175260432', }, + 'leading zero number string': { + raw: '012345', + encoded: '12345', + }, 'chr 0': { raw: String.fromCharCode(0), encoded: '49846369543417741186729467304575255505141344055555831574636310663216789168157',