Use object with null prototype for various app properties

`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.
This commit is contained in:
Evan Hahn 2022-03-17 12:34:13 -05:00 committed by Wes Todd
parent cd7d79f92a
commit 14439731f9
2 changed files with 5 additions and 4 deletions

View File

@ -61,9 +61,9 @@ var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
app.init = function init() { app.init = function init() {
var router = null; var router = null;
this.cache = {}; this.cache = Object.create(null);
this.engines = {}; this.engines = Object.create(null);
this.settings = {}; this.settings = Object.create(null);
this.defaultConfiguration(); this.defaultConfiguration();

View File

@ -5,10 +5,11 @@ var express = require('../')
describe('app', function(){ describe('app', function(){
describe('.locals', function () { describe('.locals', function () {
it('should default object', function () { it('should default object with null prototype', function () {
var app = express() var app = express()
assert.ok(app.locals) assert.ok(app.locals)
assert.strictEqual(typeof app.locals, 'object') assert.strictEqual(typeof app.locals, 'object')
assert.strictEqual(Object.getPrototypeOf(app.locals), null)
}) })
describe('.settings', function () { describe('.settings', function () {