Skip to content

Commit ef22a1c

Browse files
committed
feat: encode store name
1 parent 854ce42 commit ef22a1c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,4 +1120,30 @@ describe(`getStore`, () => {
11201120
'The `getStore` method requires the name of the store as a string or as the `name` property of an options object',
11211121
)
11221122
})
1123+
1124+
test('URL-encodes the store name', async () => {
1125+
const mockStore = new MockFetch()
1126+
.get({
1127+
headers: { authorization: `Bearer ${apiToken}` },
1128+
response: new Response(JSON.stringify({ url: signedURL })),
1129+
url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=%2Fwhat%3F`,
1130+
})
1131+
.get({
1132+
response: new Response(value),
1133+
url: signedURL,
1134+
})
1135+
1136+
globalThis.fetch = mockStore.fetch
1137+
1138+
const blobs = getStore({
1139+
name: '/what?',
1140+
token: apiToken,
1141+
siteID,
1142+
})
1143+
1144+
const string = await blobs.get(key)
1145+
expect(string).toBe(value)
1146+
1147+
expect(mockStore.fulfilled).toBeTruthy()
1148+
})
11231149
})

src/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class Store {
3333

3434
constructor(options: StoreOptions) {
3535
this.client = options.client
36-
this.name = 'deployID' in options ? `deploy:${options.deployID}` : options.name
36+
this.name = 'deployID' in options ? `deploy:${options.deployID}` : encodeURIComponent(options.name)
3737
}
3838

3939
async delete(key: string) {

0 commit comments

Comments
 (0)