From 1b8f3c00c3864733b684d1f92287f80ddeb24760 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 22 Oct 2019 10:30:03 -0300 Subject: [PATCH] replaces `en dash` with regular dash for request bodies --- lib/TelnyxResource.js | 2 +- lib/utils.js | 10 ++++++++++ test/utils.spec.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/TelnyxResource.js b/lib/TelnyxResource.js index 2077163..48e9a04 100644 --- a/lib/TelnyxResource.js +++ b/lib/TelnyxResource.js @@ -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) { diff --git a/lib/utils.js b/lib/utils.js index 919260f..041f3ec 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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: diff --git a/test/utils.spec.js b/test/utils.spec.js index 32c95e7..f7b4545 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -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() {}