mirror of
https://github.com/zebrajr/express.git
synced 2026-01-15 12:15:27 +00:00
Add "escape json" setting for res.json and res.jsonp
closes #3268 closes #3269
This commit is contained in:
committed by
Douglas Christopher Wilson
parent
628438d8d8
commit
7154014785
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user