Skip to content

Commit eccc2a5

Browse files
author
Chase Coalwell
authored
Use extended URI encoding function (#130)
1 parent 67c733a commit eccc2a5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,11 @@ private void writeResolvedPath(
263263
binding.getMember(), target);
264264
// Get the correct label to use.
265265
Segment uriLabel = uriLabels.stream().filter(s -> s.getContent().equals(memberName)).findFirst().get();
266+
writer.addImport("extendedEncodeURIComponent", "__extendedEncodeURIComponent",
267+
"@aws-sdk/smithy-client");
266268
String encodedSegment = uriLabel.isGreedyLabel()
267-
? "labelValue.split(\"/\").map(segment => encodeURIComponent(segment)).join(\"/\")"
268-
: "encodeURIComponent(labelValue)";
269+
? "labelValue.split(\"/\").map(segment => __extendedEncodeURIComponent(segment)).join(\"/\")"
270+
: "__extendedEncodeURIComponent(labelValue)";
269271

270272
// Set the label's value and throw a clear error if empty or undefined.
271273
writer.write("if (input.$L !== undefined) {", memberName).indent()
@@ -306,11 +308,14 @@ private boolean writeRequestQueryString(
306308
Model model = context.getModel();
307309
for (HttpBinding binding : queryBindings) {
308310
String memberName = symbolProvider.toMemberName(binding.getMember());
311+
writer.addImport("extendedEncodeURIComponent", "__extendedEncodeURIComponent",
312+
"@aws-sdk/smithy-client");
309313
writer.openBlock("if (input.$L !== undefined) {", "}", memberName, () -> {
310314
Shape target = model.expectShape(binding.getMember().getTarget());
311315
String queryValue = getInputValue(context, binding.getLocation(), "input." + memberName,
312316
binding.getMember(), target);
313-
writer.write("query['$L'] = $L;", binding.getLocationName(), queryValue);
317+
writer.write("query[__extendedEncodeURIComponent($S)] = __extendedEncodeURIComponent($L);",
318+
binding.getLocationName(), queryValue);
314319
});
315320
}
316321
}

0 commit comments

Comments
 (0)