-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(protocols): fix header serde, handle unset union payloads #1417
base: main
Are you sure you want to change the base?
Conversation
b2e5153
to
4821895
Compare
4821895
to
89fedbc
Compare
Location.PAYLOAD, "data", binding.getMember(), target)); | ||
} | ||
); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old:
const data: Record<string, any> | undefined = __expectUnion(await parseBody(output.body, context));
contents.nested = de_UnionPayload(data, context);
(does not handle empty output correctly)
new:
const data: Record<string, any> | undefined = await parseBody(output.body, context);
if (Object.keys(data ?? {}).length) {
contents.nested = __expectUnion(de_UnionPayload(data, context));
}
6b920c6
to
dfbbd7b
Compare
e2e28cf
to
d757a15
Compare
d757a15
to
d51fec8
Compare
part = `"${part.replace(/"/g, '\\"')}"`; | ||
} | ||
return part; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function filters the input/serialization side of list/set shape headers. A simple .join(",")
is not enough, since if the individual elements contain either the delimiter ,
or "
, they must be quoted. The internal quotes must also be escaped.
* @param value - header string value. | ||
* @returns value split by commas that aren't in quotes. | ||
*/ | ||
export const splitHeader = (value: string): string[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes over .split(",")
on the deserialization side. Splitting by commas is not enough, because commas within quotes do not count as delimiters, and once split, the items wrapped by double quotes should have those quotes removed.
Behavior specified here: https://github.com/smithy-lang/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-headers.smithy#L229-L232
{
id: "RestJsonInputAndOutputWithQuotedStringHeaders",
documentation: "Tests responses with string list header bindings that require quoting",
protocol: restJson1,
code: 200,
headers: {
"X-StringList": "\"b,c\", \"\\\"def\\\"\", a"
},
params: {
headerStringList: ["b,c", "\"def\"", "a"]
}
}
""", header, value); | ||
} else { | ||
writer.write("expect(r.headers[$S]).toBe($S);", header, value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose that we ignore comma delimiter spacing rather than changing the upstream Smithy test assertion or our and other language implementations.
this is a set of changes revealed by re-enabling the skipped protocol tests in aws/aws-sdk-js-v3#6512