WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit cb15417

Browse files
authored
Merge pull request #468 from pascalopitz/master
Sanitizing malformed device description XML
2 parents 37ab765 + cbec942 commit cb15417

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,15 @@ Helpers.ParseXml = async function (input) {
328328
})
329329
}
330330

331+
/**
332+
* Sanitizes Device Description XML async
333+
* @param {String} input The XML to be sanitized
334+
* @return {Promise}
335+
*/
336+
Helpers.SanitizeDeviceDescriptionXml = async function (input) {
337+
// This is to fix malformed xml in description see https://github.com/bencevans/node-sonos/issues/465
338+
debug('Helpers.SanitizeDeviceDescriptionXml %j', input)
339+
return input.replace(/#([\w]+)#/gm, '<!-- #$1# -->')
340+
}
341+
331342
module.exports = Helpers

lib/sonos.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ Sonos.prototype.deviceDescription = async function () {
603603
debug('Sonos.deviceDescription()')
604604
return request(`http://${this.host}:${this.port}/xml/device_description.xml`)
605605
.then(response => response.data)
606+
.then(Helpers.SanitizeDeviceDescriptionXml)
606607
.then(Helpers.ParseXml)
607608
.then(result => {
608609
return result.root.device

0 commit comments

Comments
 (0)