Skip to content
Myr

Fix handling of undefined in res.jsonp

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

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 1b2f3a0 · Browse files · 3 files+25 added−4 removed
This commit

State

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

Diff stats

3 files+25 added−4 removed

  • tests:+15 added−0 removed
  • other:+10 added−4 removed

3 files+25 added−4 removed

modified:lib/response.js+9 added-4 removed
320 unmodified lines
321322 // restrict callback charset323 callback = callback.replace(/[^\[\]\w$.]/g, '');324325 if (body === undefined) {326 // empty argument327 body = ''328 } else if (typeof body === 'string') {325 // replace chars not allowed in JavaScript that are in JSON326 body = body327 .replace(/\u2028/g, '\\u2028')328 .replace(/\u2029/g, '\\u2029');329 // replace chars not allowed in JavaScript that are in JSON330 body = body331 .replace(/\u2028/g, '\\u2028')332 .replace(/\u2029/g, '\\u2029')333 }334335 // the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"336 // the typeof check is just to reduce client error noise337 body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';
810 unmodified lines
modified:test/res.jsonp.js+15 added
154 unmodified lines
155 .expect('X-Content-Type-Options', 'nosniff')156 .expect(200, /cb\(\{"hello":"world"\}\);$/, done);157 })158159 describe('when given undefined', function () {160 it('should invoke callback with no arguments', function (done) {161 var app = express()162163 app.use(function (req, res) {164 res.jsonp(undefined)165 })166167 request(app)168 .get('/?callback=cb')169 .expect('Content-Type', 'text/javascript; charset=utf-8')170 .expect(200, /cb\(\)/, done)171 })172 })173174 describe('when given null', function () {175 it('should invoke callback with null', function (done) {176 var app = express()177
194 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * Fix handling of `undefined` in `res.jsonp`5 * Fix incorrect middleware execution with unanchored `RegExp`s6 * Fix `res.jsonp(obj, status)` deprecation message7 * Fix typo in `res.is` JSDoc8 * deps: cookie@0.4.1
3481 unmodified lines