Skip to content

Commit

Permalink
feat(xml): allow surrogate characters
Browse files Browse the repository at this point in the history
Merge branch 'stanzhengdev-xmlbuilder_update'
  • Loading branch information
Ahmad Nassri committed Feb 12, 2016
2 parents e2a659c + 0687147 commit a950c06
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/middleware/negotiate-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ module.exports = function (req, res, next) {
// am I pretty?
var spaces = req.headers['x-pretty-print'] ? parseInt(req.headers['x-pretty-print'], 10) : 2

var xmlOpts = {
pretty: (spaces > 0),
indent: new Array(spaces).join(' '),
newline: '\n'
}

function YAMLResponse () {
if (typeof res.body === 'string') {
return res.send(res.body)
Expand All @@ -27,16 +33,12 @@ module.exports = function (req, res, next) {
}

function XMLResponse () {
res.send(XML.create(res.bodyXmlObj || res.body).end({
pretty: (spaces > 0),
indent: new Array(spaces).join(' '),
newline: '\n'
}))
res.send(XML.create(res.bodyXmlObj || res.body, { allowSurrogateChars: true }).end(xmlOpts))
}

function HTMLResponse () {
req.app.locals.moment = moment

XML.create(res.bodyXmlObj, { allowSurrogateChars: true })
res.render(res.view || 'default', {
req: req,
res: res,
Expand All @@ -46,7 +48,7 @@ module.exports = function (req, res, next) {

json: JSON.stringify(res.body, null, 2),

xml: XML.create(res.bodyXmlObj || res.body).end()
xml: XML.create(res.bodyXmlObj || res.body, { allowSurrogateChars: true }).end(xmlOpts)
}
})
}
Expand Down

0 comments on commit a950c06

Please sign in to comment.