Skip to content

Commit

Permalink
replaces en dash with regular dash for request bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Oct 22, 2019
1 parent 38d627c commit 1b8f3c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/TelnyxResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ TelnyxResource.prototype = {
} else if (method == 'DELETE') {
makeRequestWithData(null, '');
} else {
makeRequestWithData(null, JSON.stringify(data || {}));
makeRequestWithData(null, utils.stringifyRequestBodyData(data || {}));
}

function retryRequest(requestFn, headers, requestRetries) {
Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ var utils = module.exports = {
.replace(/%5B/g, '[').replace(/%5D/g, ']');
},

/**
* Stringifies an Object, accommodating nested objects
* (forming the conventional key 'parent[child]=value')
*/
stringifyRequestBodyData: function(data) {
return JSON.stringify(data)
// encode EM Dash (ENGDESK-2825)
.replace(//g, '-');
},

/**
* Outputs a new function with interpolated object property values.
* Use like so:
Expand Down
11 changes: 11 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ describe('utils', function() {
});
});

describe('stringifyRequestBodyData', function() {
it('Handles EM Dash', function() {
expect(utils.stringifyRequestBodyData({
from: 'NUMBER',
text: 'Hi Susan! This is Collin with Polling for Progress – do you ?',
to: 'NUMBER',
webhook_url: ''
})).to.equal('{"from":"NUMBER","text":"Hi Susan! This is Collin with Polling for Progress - do you ?","to":"NUMBER","webhook_url":""}');
});
});

describe('protoExtend', function() {
it('Provides an extension mechanism', function() {
function A() {}
Expand Down

0 comments on commit 1b8f3c0

Please sign in to comment.