Skip to content

Commit

Permalink
Fix xml special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
panzhi33 authored and xdkxlk committed Nov 17, 2021
1 parent 0acc658 commit 340f78c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.extract = function extract (arr) {

function format (params) {
if (typeof params === 'string') {
return params;
return `<![CDATA[${params}]]>`;
}

var xml = '';
Expand All @@ -38,7 +38,7 @@ function format (params) {
if (typeof value === 'object') {
xml += `<${key}>${format(value)}</${key}>`;
} else {
xml += `<${key}>${value}</${key}>`;
xml += `<${key}><![CDATA[${value}]]></${key}>`;
}
});
return xml;
Expand Down
10 changes: 10 additions & 0 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,15 @@ describe('mq client test', function () {
const ackresp = await transProducer.commit(message.ReceiptHandle);
expect(ackresp.code).to.be(204);
});

it('publishMessage with & should ok', async function() {
var msgProperties = new MessageProperties();
const response = await producer.publishMessage('test message with &', '', msgProperties);
expect(response).to.be.ok();
expect(response.code).to.be(201);
const message = response.body;
expect(message).to.have.property('MessageId');
expect(message).to.have.property('MessageBodyMD5');
});
});
});

0 comments on commit 340f78c

Please sign in to comment.