Skip to content

Commit

Permalink
fix(smithy-client): use uppercase for percent encodings (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jun 18, 2021
1 parent 122c139 commit 6ef34b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/smithy-client/src/extended-encode-uri-component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";

describe(extendedEncodeURIComponent.name, () => {
const encodedValues: [string, string][] = [
["!", "%21"],
["'", "%27"],
["(", "%28"],
[")", "%29"],
["*", "%2A"],
];

const verify = (table: [string, string][]) => {
it.each(table)(`encodes %s as %s`, (input, output) => {
expect(extendedEncodeURIComponent(input)).toStrictEqual(output);
});
};

verify(encodedValues);
verify([encodedValues.reduce((acc, [input, output]) => [acc[0].concat(input), acc[1].concat(output)], ["", ""])]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*/
export function extendedEncodeURIComponent(str: string): string {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return "%" + c.charCodeAt(0).toString(16);
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
});
}

0 comments on commit 6ef34b5

Please sign in to comment.