Skip to content
Myr

fix jsonp whitespace escape. Closes #1132

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Guillermo Rauch · committed by TJ Holowaychuk · parent 33eaa83 · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−1 removed

  • tests:+16 added−0 removed
  • other:+3 added−1 removed

2 files+19 added−1 removed

modified:lib/response.js+3 added-1 removed
221 unmodified lines
222 // settings223 var app = this.app;224 var replacer = app.get('json replacer');225 var spaces = app.get('json spaces');226 var body = JSON.stringify(obj, replacer, spaces);226 var body = JSON.stringify(obj, replacer, spaces)227 .replace(/\u2028/g, '\\u2028')228 .replace(/\u2029/g, '\\u2029');229 var callback = this.req.query[app.get('jsonp callback name')];230231 // content-type232 this.charset = this.charset || 'utf-8';
488 unmodified lines
modified:test/res.jsonp.js+16 added
69 unmodified lines
70 done();71 })72 })7374 it('should escape utf whitespace', function(done){75 var app = express();7677 app.use(function(req, res){78 res.jsonp({ str: '\u2028 \u2029 woot' });79 });8081 request(app)82 .get('/?callback=foo')83 .end(function(err, res){84 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');85 res.text.should.equal('foo && foo({"str":"\\u2028 \\u2029 woot"});');86 done();87 });88 });8990 describe('when given primitives', function(){91 it('should respond with json', function(done){92 var app = express();93
143 unmodified lines