diff --git a/lib/middleware/negotiate-content.js b/lib/middleware/negotiate-content.js index 5d609ddf..849b2344 100644 --- a/lib/middleware/negotiate-content.js +++ b/lib/middleware/negotiate-content.js @@ -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) @@ -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, @@ -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) } }) }