Skip to content

Commit 7c42fcc

Browse files
author
childish-sambino
authored
fix: encode URL path params (twilio#94)
When referencing a resource by a unique name with non-safe characters, it needs to be URI-encoded or the request will fail.
1 parent f4826fb commit 7c42fcc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/services/open-api-client.js

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class OpenApiClient {
8383

8484
if (doesObjectHaveProperty(opts.pathParams, pathNode)) {
8585
value = opts.pathParams[pathNode];
86+
value = encodeURIComponent(value);
8687
}
8788

8889
logger.debug(`pathNode=${pathNode}, value=${value}`);

test/services/twilio-api/twilio-client.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ describe('services', () => {
232232
expect(httpClient.lastRequest.data).to.eql(qs.stringify({ EmergencyEnabled: 'true' }));
233233
});
234234

235+
test
236+
.nock('https://api.twilio.com', api => {
237+
api.get(`/2010-04-01/Accounts/${accountSid}/Calls/hey%23there%3F.json`).reply(200, {
238+
status: 'in-progress'
239+
});
240+
})
241+
.it('encodes non-safe path param characters', async () => {
242+
const response = await client.fetch({
243+
domain: 'api',
244+
path: '/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json',
245+
pathParams: { Sid: 'hey#there?' }
246+
});
247+
248+
expect(response).to.eql({ status: 'in-progress' });
249+
});
250+
235251
/* eslint-disable max-nested-callbacks */
236252
describe('getLimit', () => {
237253
test.it('gets the limit', () => {

0 commit comments

Comments
 (0)