Skip to content

Commit

Permalink
Stringify array attributes as space delimited
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeltonen committed Nov 6, 2019
1 parent 6f514fb commit a068ac2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/twiml/TwiML.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/twiml/VoiceResponse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ describe('create voice response TwiML', function() {
expect(actual.toString()).toEqual('<?xml version="1.0" encoding="UTF-8"?><Response><Dial timeout="5"><Number>+11234567890</Number></Dial><Reject/><Redirect>www.twilio.com</Redirect><Pause length="5"/></Response>');
});

it('should serialize array attributes as space delimited', function() {
var actual = new VoiceResponse();
actual.dial().number({ statusCallbackEvents: ["initiated", "ringing"] }, '+11234567890')

expect(actual.toString()).toEqual('<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number statusCallbackEvents="initiated ringing">+11234567890</Number></Dial></Response>');
});

it('should allow adding arbitrary text to leaf nodes', function() {
var actual = new VoiceResponse();
actual.hangup().addText('extra text');
Expand Down

0 comments on commit a068ac2

Please sign in to comment.