diff --git a/packages/smithy-client/src/split-header.spec.ts b/packages/smithy-client/src/split-header.spec.ts index fd6933fc5fc..608abf76a06 100644 --- a/packages/smithy-client/src/split-header.spec.ts +++ b/packages/smithy-client/src/split-header.spec.ts @@ -7,9 +7,16 @@ describe(splitHeader.name, () => { expect(splitHeader("a, b, c")).toEqual(["a", "b", "c"]); expect(splitHeader("a , b , c")).toEqual(["a", "b", "c"]); expect(splitHeader(`a , b , " c "`)).toEqual(["a", "b", " c "]); + expect(splitHeader(` a , , b`)).toEqual(["a", "", "b"]); + expect(splitHeader(`,,`)).toEqual(["", "", ""]); + expect(splitHeader(` , , `)).toEqual(["", "", ""]); }); 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); }