trims leading and trailing whitespace

This commit is contained in:
Nebel 2024-09-18 14:48:24 +09:00
parent ddcb93da0c
commit 5ad019029b
Signed by: nebel
GPG key ID: 79807D08C6EF6460
2 changed files with 4 additions and 5 deletions

View file

@ -51,13 +51,12 @@ export class IntegrityMetadata implements IntegrityMetadataLike {
alg: PrioritizedHashAlgorithm; alg: PrioritizedHashAlgorithm;
val: string; val: string;
opt: string[]; opt: string[];
constructor(integrity: string | null | undefined) {
constructor(integrity: string) {
const { const {
alg = "", alg = "",
val = "", val = "",
opt, opt,
} = IntegrityMetadataRegex.exec(integrity)?.groups ?? {}; } = IntegrityMetadataRegex.exec((integrity ?? "").trim())?.groups ?? {};
Object.assign(this, { Object.assign(this, {
alg, alg,

View file

@ -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( 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( assert.deepEqual(