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 14c935b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/smithy-client/src/split-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([`"`]);
});
});
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 14c935b

Please sign in to comment.