From 5ad019029bc22ff38820c682c66519a352eba58e Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Wed, 18 Sep 2024 14:48:24 +0900 Subject: [PATCH] trims leading and trailing whitespace --- src/index.ts | 5 ++--- test/integrity-metadata/constructor.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3f5b411..7a1fed4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,13 +51,12 @@ export class IntegrityMetadata implements IntegrityMetadataLike { alg: PrioritizedHashAlgorithm; val: string; opt: string[]; - - constructor(integrity: string) { + constructor(integrity: string | null | undefined) { const { alg = "", val = "", opt, - } = IntegrityMetadataRegex.exec(integrity)?.groups ?? {}; + } = IntegrityMetadataRegex.exec((integrity ?? "").trim())?.groups ?? {}; Object.assign(this, { alg, diff --git a/test/integrity-metadata/constructor.js b/test/integrity-metadata/constructor.js index c6df9bc..f628ee4 100644 --- a/test/integrity-metadata/constructor.js +++ b/test/integrity-metadata/constructor.js @@ -64,9 +64,9 @@ test.todo("accepts an IntegrityMetadata like object as input", function () { ); }); -test.todo("trims leading and trailing whitespace", function () { +test("trims leading and trailing whitespace", function () { const integrityMetadata = new IntegrityMetadata( - "\t sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=\u0020\u00a0\u1680\u180e\u2000\u2001\u2002\u3000", + "\t sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=\u0020\u00a0\u1680\u2000\u2001\u2002\u3000", ); assert.deepEqual(