Add "escape json" setting for res.json and res.jsonp

closes #3268
closes #3269
This commit is contained in:
Greg Guthe
2017-04-05 17:42:09 -04:00
committed by Douglas Christopher Wilson
parent 628438d8d8
commit 7154014785
4 changed files with 76 additions and 5 deletions

View File

@@ -242,6 +242,28 @@ describe('res', function(){
})
})
describe('"json escape" setting', function () {
it('should be undefined by default', function () {
var app = express()
assert.strictEqual(app.get('json escape'), undefined)
})
it('should unicode escape HTML-sniffing characters', function (done) {
var app = express()
app.enable('json escape')
app.use(function (req, res) {
res.jsonp({ '&': '\u2028<script>\u2029' })
})
request(app)
.get('/?callback=foo')
.expect('Content-Type', 'text/javascript; charset=utf-8')
.expect(200, /foo\({"\\u0026":"\\u2028\\u003cscript\\u003e\\u2029"}\)/, done)
})
})
describe('"json replacer" setting', function(){
it('should be passed to JSON.stringify()', function(done){
var app = express();