Skip to content

Commit

Permalink
fix: encode URL path params (twilio#94)
Browse files Browse the repository at this point in the history
When referencing a resource by a unique name with non-safe characters, it needs to be URI-encoded or the request will fail.
  • Loading branch information
childish-sambino committed Jun 25, 2020
1 parent f4826fb commit 7c42fcc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/services/open-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class OpenApiClient {

if (doesObjectHaveProperty(opts.pathParams, pathNode)) {
value = opts.pathParams[pathNode];
value = encodeURIComponent(value);
}

logger.debug(`pathNode=${pathNode}, value=${value}`);
Expand Down
16 changes: 16 additions & 0 deletions test/services/twilio-api/twilio-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ describe('services', () => {
expect(httpClient.lastRequest.data).to.eql(qs.stringify({ EmergencyEnabled: 'true' }));
});

test
.nock('https://api.twilio.com', api => {
api.get(`/2010-04-01/Accounts/${accountSid}/Calls/hey%23there%3F.json`).reply(200, {
status: 'in-progress'
});
})
.it('encodes non-safe path param characters', async () => {
const response = await client.fetch({
domain: 'api',
path: '/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json',
pathParams: { Sid: 'hey#there?' }
});

expect(response).to.eql({ status: 'in-progress' });
});

/* eslint-disable max-nested-callbacks */
describe('getLimit', () => {
test.it('gets the limit', () => {
Expand Down

0 comments on commit 7c42fcc

Please sign in to comment.