Skip to content

Commit 403bdc4

Browse files
adamthom-amznsrchase
authored andcommitted
Revert decoding of query parameters
HttpRequest, as used by the SDK, does not contain encoded keys or values. APIGateway's events also contain decoded query string keys and values. The only thing that needs decoding is path segments, because the path is stored un-split and thus it cannot be stored decoded (or / and %2F would be indistinguishable). This partially reverts 24f2ead
1 parent 5187331 commit 403bdc4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,9 +1689,8 @@ private void readDirectQueryBindings(GenerationContext context, List<HttpBinding
16891689
writer.openBlock("if (query[$S] !== undefined) {", "}", binding.getLocationName(), () -> {
16901690
Shape target = context.getModel().expectShape(binding.getMember().getTarget());
16911691
if (target instanceof CollectionShape) {
1692-
writer.write("const decoded = Array.isArray(query[$1S]) ? (query[$1S] as string[])"
1693-
+ ".map(e => decodeURIComponent(e)) : [decodeURIComponent(query[$1S] as string)];",
1694-
binding.getLocationName());
1692+
writer.write("const queryValue = Array.isArray(query[$1S]) ? (query[$1S] as string[])"
1693+
+ " : [query[$1S] as string];", binding.getLocationName());
16951694
} else {
16961695
writer.addImport("SerializationException",
16971696
"__SerializationException",
@@ -1701,10 +1700,10 @@ private void readDirectQueryBindings(GenerationContext context, List<HttpBinding
17011700
() -> {
17021701
writer.write("throw new __SerializationException();");
17031702
});
1704-
writer.write("const decoded = decodeURIComponent(query[$1S] as string);",
1703+
writer.write("const queryValue = query[$1S] as string;",
17051704
binding.getLocationName());
17061705
}
1707-
String queryValue = getOutputValue(context, binding.getLocation(), "decoded",
1706+
String queryValue = getOutputValue(context, binding.getLocation(), "queryValue",
17081707
binding.getMember(), target);
17091708
writer.write("contents.$L = $L;", memberName, queryValue);
17101709
});
@@ -1721,12 +1720,12 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
17211720
valueType = "string[]";
17221721
}
17231722
writer.write("let parsedQuery: { [key: string]: $L } = {}", valueType);
1724-
String parsedValue = getOutputValue(context, mappedBinding.getLocation(),
1725-
"decoded", target.getValue(), valueShape);
17261723
writer.openBlock("for (const [key, value] of Object.entries(query)) {", "}", () -> {
1724+
final String parsedValue;
17271725
if (valueShape instanceof CollectionShape) {
1728-
writer.write("const decoded = Array.isArray(value) ? (value as string[])"
1729-
+ ".map(e => decodeURIComponent(e)) : [decodeURIComponent(value as string)];");
1726+
writer.write("const valueArray = Array.isArray(value) ? (value as string[]) : [value as string];");
1727+
parsedValue = getOutputValue(context, mappedBinding.getLocation(),
1728+
"valueArray", target.getValue(), valueShape);
17301729
} else {
17311730
writer.addImport("SerializationException",
17321731
"__SerializationException",
@@ -1735,9 +1734,10 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
17351734
() -> {
17361735
writer.write("throw new __SerializationException();");
17371736
});
1738-
writer.write("const decoded = decodeURIComponent(value as string);");
1737+
parsedValue = getOutputValue(context, mappedBinding.getLocation(),
1738+
"value as string", target.getValue(), valueShape);
17391739
}
1740-
writer.write("parsedQuery[decodeURIComponent(key)] = $L;", parsedValue);
1740+
writer.write("parsedQuery[key] = $L;", parsedValue);
17411741
});
17421742
String memberName = context.getSymbolProvider().toMemberName(mappedBinding.getMember());
17431743
writer.write("contents.$L = parsedQuery;", memberName);

0 commit comments

Comments
 (0)