Skip to content

Commit 3168eda

Browse files
committed
additional test cases for split-header
1 parent 2ab214d commit 3168eda

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/smithy-client/src/split-header.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ describe(splitHeader.name, () => {
77
expect(splitHeader("a, b, c")).toEqual(["a", "b", "c"]);
88
expect(splitHeader("a , b , c")).toEqual(["a", "b", "c"]);
99
expect(splitHeader(`a , b , " c "`)).toEqual(["a", "b", " c "]);
10+
expect(splitHeader(` a , , b`)).toEqual(["a", "", "b"]);
11+
expect(splitHeader(`,,`)).toEqual(["", "", ""]);
12+
expect(splitHeader(` , , `)).toEqual(["", "", ""]);
1013
});
1114
it("should split a string by commas that are not in quotes, and remove outer quotes", () => {
1215
expect(splitHeader('"b,c", "\\"def\\"", a')).toEqual(["b,c", '"def"', "a"]);
1316
expect(splitHeader('"a,b,c", ""def"", "a,b ,c"')).toEqual(["a,b,c", '"def"', "a,b ,c"]);
17+
expect(splitHeader(`""`)).toEqual([``]);
18+
expect(splitHeader(``)).toEqual([``]);
19+
expect(splitHeader(`\\"`)).toEqual([`"`]);
20+
expect(splitHeader(`"`)).toEqual([`"`]);
1421
});
1522
});

packages/smithy-client/src/split-header.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const splitHeader = (value: string): string[] => {
3434
return values.map((v) => {
3535
v = v.trim();
3636
const z = v.length;
37+
if (z < 2) {
38+
return v;
39+
}
3740
if (v[0] === `"` && v[z - 1] === `"`) {
3841
v = v.slice(1, z - 1);
3942
}

0 commit comments

Comments
 (0)