Skip to content
Myr

feat: Allow passing null or undefined as the value for options in app.render (#6903)

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

* fix: allow null options in app.render * fix: ensure options are initialized to an empty object in app.render * docs: add history entry ---------

authored by AkaHarshit · committed by GitHub · parent a479419 · Browse files · 3 files+25 added−1 removed
This commit

State

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

Trailers

  • Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>

Diff stats

3 files+25 added−1 removed

  • tests:+18 added−0 removed
  • other:+7 added−1 removed

3 files+25 added−1 removed

modified:lib/application.js+1 added-1 removed
521 unmodified lines
522app.render = function render(name, options, callback) {523 var cache = this.cache;524 var done = callback;525 var engines = this.engines;526 var opts = options;526 var opts = options || {};527 var view;528529 // support callback function as second arg530 if (typeof options === 'function') {
101 unmodified lines
modified:test/app.render.js+18 added
329 unmodified lines
330 done();331 })332 })333334 it('should accept null or undefined options', function (done) {335 var app = createApp()336337 app.set('views', path.join(__dirname, 'fixtures'))338 app.locals.user = { name: 'tobi' }339340 app.render('user.tmpl', null, function (err, str) {341 if (err) return done(err);342 assert.strictEqual(str, '<p>tobi</p>')343344 app.render('user.tmpl', undefined, function (err2, str2) {345 if (err2) return done(err2);346 assert.strictEqual(str2, '<p>tobi</p>')347 done()348 })349 })350 })351352 describe('caching', function(){353 it('should cache with cache option', function(done){354 var app = express();355 var count = 0;
37 unmodified lines
modified:History.md+6 added
2 unmodified lines
3## 🚀 Improvements45* Improve HTML structure in `res.redirect()` responses when HTML format is accepted by adding `<!DOCTYPE html>`, `<title>`, and `<body>` tags for better browser compatibility - by [@Bernice55231](https://github.com/Bernice55231) in [#5167](https://github.com/expressjs/express/pull/5167)67* When calling `app.render` with options set to null, the locals object is handled correctly, preventing unexpected errors and making the method behave the same as when options is omitted or an empty object is passed - by [AkaHarshit](https://github.com/AkaHarshit) in [#6903](https://github.com/expressjs/express/pull/6903)89 ```js10 app.render('index', null, callback); // now works as expected11 ```1213## ⚡ Performance1415* Avoid duplicate Content-Type header processing in `res.send()` when sending string responses without an explicit Content-Type header - by [@bjohansebas](https://github.com/bjohansebas) in [#6991](https://github.com/expressjs/express/pull/6991)16
3871 unmodified lines