Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed Mar 27, 2024
1 parent 23ccb77 commit 4b2bce4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/__tests__/encode-rfc3986.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { encodeRfc3986 } from "../encode-rfc3986.js";

describe("encodeRfc3986", () => {
it("should encode reserved characters", () => {
// * ! ' ( )
// * ! ' ( )
const encoded = encodeRfc3986("* ! ' ( )");
expect(encoded).toEqual("%2A %21 %27 %28 %29");
});

it("should not encode other characters", () => {
// A–Z a–z 0–9 - _ . ~ ; / ? : @ & = + $ , #
const str =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- _ . ~ ; / ? : @ & = + $ , #";
const encoded = encodeRfc3986(str);
expect(encoded).toEqual(str);
});
it("should not encode other characters", () => {
// A–Z a–z 0–9 - _ . ~ ; / ? : @ & = + $ , #
const str =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- _ . ~ ; / ? : @ & = + $ , #";
const encoded = encodeRfc3986(str);
expect(encoded).toEqual(str);
});
});
30 changes: 15 additions & 15 deletions src/create-signed-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import { getFetchFn } from "./get-fetch.js";
import { getHeaders } from "./get-headers.js";

export type SignedFetcherOptions = {
service: string;
region?: string;
credentials?: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
fetch?: typeof fetch;
/**
* Automatically encode the request path and query string according to RFC 3986.
* This might be necessary for AWS services that require strict adherence to the RFC 3986 standard.
* For example, AWS API Gateway requires the path and query string to be encoded according to RFC 3986,
* otherwise it will return a 403 error because the calculated does not match the signature you provided.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 | Encoding for RFC3986}
*/
encodeRfc3986?: boolean;
};
service: string;
region?: string;
credentials?: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
fetch?: typeof fetch;
/**
* Automatically encode the request path and query string according to RFC 3986.
* This might be necessary for AWS services that require strict adherence to the RFC 3986 standard.
* For example, AWS API Gateway requires the path and query string to be encoded according to RFC 3986,
* otherwise it will return a 403 error because the calculated does not match the signature you provided.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#encoding_for_rfc3986 | Encoding for RFC3986}
*/
encodeRfc3986?: boolean;
};

export type CreateSignedFetcher = (init: SignedFetcherOptions) => typeof fetch;

Expand Down Expand Up @@ -51,7 +51,7 @@ export const createSignedFetcher: CreateSignedFetcher = (
: input.url,
);

// encode path and query string according to RFC 3986
// encode path and query string according to RFC 3986
if (opts.encodeRfc3986) {
url.pathname = encodeRfc3986(url.pathname);
url.searchParams.forEach((value, key) => {
Expand Down

0 comments on commit 4b2bce4

Please sign in to comment.