Skip to content

Commit

Permalink
Merge pull request #468 from pascalopitz/master
Browse files Browse the repository at this point in the history
Sanitizing malformed device description XML
  • Loading branch information
svrooij authored Jun 29, 2020
2 parents 37ab765 + cbec942 commit cb15417
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,15 @@ Helpers.ParseXml = async function (input) {
})
}

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

module.exports = Helpers
1 change: 1 addition & 0 deletions lib/sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ Sonos.prototype.deviceDescription = async function () {
debug('Sonos.deviceDescription()')
return request(`http://${this.host}:${this.port}/xml/device_description.xml`)
.then(response => response.data)
.then(Helpers.SanitizeDeviceDescriptionXml)
.then(Helpers.ParseXml)
.then(result => {
return result.root.device
Expand Down

0 comments on commit cb15417

Please sign in to comment.