Skip to content

Commit

Permalink
Use object with null prototype for various app properties
Browse files Browse the repository at this point in the history
`app.cache`, `app.engines`, and `app.settings` are now created with
`Object.create(null)` instead of `{}`.

This also updates a test to ensure that `app.locals` is created the same
way.
  • Loading branch information
EvanHahn authored and wesleytodd committed Apr 29, 2024
1 parent cd7d79f commit 1443973
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/application.js
Expand Up @@ -61,9 +61,9 @@ var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
app.init = function init() {
var router = null;

this.cache = {};
this.engines = {};
this.settings = {};
this.cache = Object.create(null);
this.engines = Object.create(null);
this.settings = Object.create(null);

this.defaultConfiguration();

Expand Down
3 changes: 2 additions & 1 deletion test/app.locals.js
Expand Up @@ -5,10 +5,11 @@ var express = require('../')

describe('app', function(){
describe('.locals', function () {
it('should default object', function () {
it('should default object with null prototype', function () {
var app = express()
assert.ok(app.locals)
assert.strictEqual(typeof app.locals, 'object')
assert.strictEqual(Object.getPrototypeOf(app.locals), null)
})

describe('.settings', function () {
Expand Down

0 comments on commit 1443973

Please sign in to comment.