-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(protocols): fix header serde, handle unset union payloads (#1417)
- Loading branch information
Showing
12 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@smithy/middleware-compression": patch | ||
--- | ||
|
||
comma spacing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@smithy/smithy-client": minor | ||
--- | ||
|
||
add quoteHeader function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { quoteHeader } from "./quote-header"; | ||
|
||
describe(quoteHeader.name, () => { | ||
it("should not wrap header elements that don't include the delimiter or double quotes", () => { | ||
expect(quoteHeader("bc")).toBe("bc"); | ||
}); | ||
|
||
it("should wrap header elements that include the delimiter", () => { | ||
expect(quoteHeader("b,c")).toBe('"b,c"'); | ||
}); | ||
|
||
it("should wrap header elements that include double quotes", () => { | ||
expect(quoteHeader(`"bc"`)).toBe('"\\"bc\\""'); | ||
}); | ||
|
||
it("should wrap header elements that include the delimiter and double quotes", () => { | ||
expect(quoteHeader(`"b,c"`)).toBe('"\\"b,c\\""'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @public | ||
* @param part - header list element | ||
* @returns quoted string if part contains delimiter. | ||
*/ | ||
export function quoteHeader(part: string) { | ||
if (part.includes(",") || part.includes('"')) { | ||
part = `"${part.replace(/"/g, '\\"')}"`; | ||
} | ||
return part; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { splitHeader } from "./split-header"; | ||
|
||
describe(splitHeader.name, () => { | ||
it("should split a string by commas and trim only the comma delimited outer values", () => { | ||
expect(splitHeader("abc")).toEqual(["abc"]); | ||
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 , " 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([`"`]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @param value - header string value. | ||
* @returns value split by commas that aren't in quotes. | ||
*/ | ||
export const splitHeader = (value: string): string[] => { | ||
const z = value.length; | ||
const values = []; | ||
|
||
let withinQuotes = false; | ||
let prevChar = undefined; | ||
let anchor = 0; | ||
|
||
for (let i = 0; i < z; ++i) { | ||
const char = value[i]; | ||
switch (char) { | ||
case `"`: | ||
if (prevChar !== "\\") { | ||
withinQuotes = !withinQuotes; | ||
} | ||
break; | ||
case ",": | ||
if (!withinQuotes) { | ||
values.push(value.slice(anchor, i)); | ||
anchor = i + 1; | ||
} | ||
break; | ||
default: | ||
} | ||
prevChar = char; | ||
} | ||
|
||
values.push(value.slice(anchor)); | ||
|
||
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); | ||
} | ||
return v.replace(/\\"/g, '"'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters