From a068ac202769b97b0f6392585fe7088bcdabba19 Mon Sep 17 00:00:00 2001 From: Mikko Peltonen Date: Wed, 6 Nov 2019 19:37:45 +0200 Subject: [PATCH] Stringify array attributes as space delimited Fixes #497 --- lib/twiml/TwiML.js | 13 ++++++++++++- spec/unit/twiml/VoiceResponse.spec.js | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/twiml/TwiML.js b/lib/twiml/TwiML.js index a89a418140..d0d94842cf 100644 --- a/lib/twiml/TwiML.js +++ b/lib/twiml/TwiML.js @@ -8,7 +8,18 @@ var builder = require('xmlbuilder'); /* jshint ignore:line */ */ /* jshint ignore:end */ function TwiML() { - this.response = builder.create('Response').dec('1.0', 'UTF-8'); + this.response = builder.create('Response', { + stringify: { + attValue: stringifyAttValue + } + }).dec('1.0', 'UTF-8'); +} + +function stringifyAttValue(value) { + if (Array.isArray(value)) { + return value.join(' '); + } + return value; } /* jshint ignore:start */ diff --git a/spec/unit/twiml/VoiceResponse.spec.js b/spec/unit/twiml/VoiceResponse.spec.js index 064e0285b9..f6a708506d 100644 --- a/spec/unit/twiml/VoiceResponse.spec.js +++ b/spec/unit/twiml/VoiceResponse.spec.js @@ -165,6 +165,13 @@ describe('create voice response TwiML', function() { expect(actual.toString()).toEqual('+11234567890www.twilio.com'); }); + it('should serialize array attributes as space delimited', function() { + var actual = new VoiceResponse(); + actual.dial().number({ statusCallbackEvents: ["initiated", "ringing"] }, '+11234567890') + + expect(actual.toString()).toEqual('+11234567890'); + }); + it('should allow adding arbitrary text to leaf nodes', function() { var actual = new VoiceResponse(); actual.hangup().addText('extra text');