From 14c935bafc2b4092e9107ea291afb44c2f46ddb6 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 1 Oct 2024 20:57:22 +0000 Subject: [PATCH] additional test cases for split-header --- packages/smithy-client/src/split-header.spec.ts | 4 ++++ packages/smithy-client/src/split-header.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/packages/smithy-client/src/split-header.spec.ts b/packages/smithy-client/src/split-header.spec.ts index fd6933fc5fc..f13cf54169a 100644 --- a/packages/smithy-client/src/split-header.spec.ts +++ b/packages/smithy-client/src/split-header.spec.ts @@ -11,5 +11,9 @@ describe(splitHeader.name, () => { it("should split a string by commas that are not in quotes, and remove outer quotes", () => { expect(splitHeader('"b,c", "\\"def\\"", a')).toEqual(["b,c", '"def"', "a"]); expect(splitHeader('"a,b,c", ""def"", "a,b ,c"')).toEqual(["a,b,c", '"def"', "a,b ,c"]); + expect(splitHeader(`""`)).toEqual([``]); + expect(splitHeader(``)).toEqual([``]); + expect(splitHeader(`\\"`)).toEqual([`"`]); + expect(splitHeader(`"`)).toEqual([`"`]); }); }); diff --git a/packages/smithy-client/src/split-header.ts b/packages/smithy-client/src/split-header.ts index da61b573b59..e76aa577de6 100644 --- a/packages/smithy-client/src/split-header.ts +++ b/packages/smithy-client/src/split-header.ts @@ -34,6 +34,9 @@ export const splitHeader = (value: string): string[] => { return values.map((v) => { v = v.trim(); const z = v.length; + if (z < 2) { + return v; + } if (v[0] === `"` && v[z - 1] === `"`) { v = v.slice(1, z - 1); }