Skip to content

Commit

Permalink
fix: consistently encode query (smithy-lang#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell authored and srchase committed Jun 16, 2023
1 parent 0923246 commit 87768ba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/querystring-builder/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryParameterBag } from "@aws-sdk/types";
import { escapeUri, escapeUriPath } from "@aws-sdk/util-uri-escape";
import { escapeUri } from "@aws-sdk/util-uri-escape";

export function buildQueryString(query: QueryParameterBag): string {
const parts: string[] = [];
Expand Down
1 change: 1 addition & 0 deletions packages/signature-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@aws-sdk/is-array-buffer": "^1.0.0-alpha.2",
"@aws-sdk/types": "^1.0.0-alpha.4",
"@aws-sdk/util-hex-encoding": "^1.0.0-alpha.2",
"@aws-sdk/util-uri-escape": "^1.0.0-alpha.2",
"tslib": "^1.8.0"
},
"devDependencies": {
Expand Down
9 changes: 3 additions & 6 deletions packages/signature-v4/src/getCanonicalQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SIGNATURE_HEADER } from "./constants";
import { HttpRequest } from "@aws-sdk/types";
import { escapeUri } from "@aws-sdk/util-uri-escape";

/**
* @internal
Expand All @@ -15,18 +16,14 @@ export function getCanonicalQuery({ query = {} }: HttpRequest): string {
keys.push(key);
const value = query[key];
if (typeof value === "string") {
serialized[key] = `${encodeURIComponent(key)}=${encodeURIComponent(
value
)}`;
serialized[key] = `${escapeUri(key)}=${escapeUri(value)}`;
} else if (Array.isArray(value)) {
serialized[key] = value
.slice(0)
.sort()
.reduce(
(encoded: Array<string>, value: string) =>
encoded.concat([
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
]),
encoded.concat([`${escapeUri(key)}=${escapeUri(value)}`]),
[]
)
.join("&");
Expand Down

0 comments on commit 87768ba

Please sign in to comment.