Skip to content

Commit

Permalink
feat: extended URI encoding (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed Feb 11, 2020
1 parent c6477a1 commit 983027f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ static void generateBuildFormUrlencodedString(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();

// Write a single function to handle combining a map in to a valid query string.
writer.addImport("extendedEncodeURIComponent", "__extendedEncodeURIComponent", "@aws-sdk/smithy-client");
writer.openBlock("const buildFormUrlencodedString = (entries: any): string => {", "}", () -> {
writer.openBlock("return Object.keys(entries).map(", ").join(\"&\");", () ->
writer.write("key => encodeURIComponent(key) + '=' + encodeURIComponent(entries[key])"));
writer.write("key => __extendedEncodeURIComponent(key) + '=' + "
+ "__extendedEncodeURIComponent(entries[key])"));
});
writer.write("");
}
Expand Down
9 changes: 9 additions & 0 deletions packages/smithy-client/src/extended-encode-uri-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Function that wraps encodeURIComponent to encode additional characters
* to fully adhere to RFC 3986.
*/
export function extendedEncodeURIComponent(str: string): string {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return "%" + c.charCodeAt(0).toString(16);
});
}
1 change: 1 addition & 0 deletions packages/smithy-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./document-type";
export * from "./exception";
export * from "./isa";
export * from "./lazy-json";
export * from "./extended-encode-uri-component";

0 comments on commit 983027f

Please sign in to comment.