Skip to content

Commit

Permalink
additional test cases for split-header
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 1, 2024
1 parent 2ab214d commit 3168eda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/smithy-client/src/split-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([`"`]);
});
});
3 changes: 3 additions & 0 deletions packages/smithy-client/src/split-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3168eda

Please sign in to comment.