From 1d27cf0e056edebc132008f2182778bf53379520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 4 Nov 2015 15:47:55 +0100 Subject: [PATCH] executor: preserve RegExps in middleware paths Fix interpolateVariables() to skip objects with a non-default constructor, for example RegExp or Date. --- lib/executor.js | 4 ++++ test/executor.test.js | 32 +++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/executor.js b/lib/executor.js index aa61c5a..c44ca75 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -354,6 +354,10 @@ function getUpdatedConfigObject(app, config) { if (Array.isArray(config)) return config.map(interpolateVariables); + // Not a plain object. Examples: RegExp, Date, + if (!config.constructor || config.constructor !== Object) + return config; + // recurse into object props var interpolated = {}; Object.keys(config).forEach(function(configKey) { diff --git a/test/executor.test.js b/test/executor.test.js index 471aff5..42d2ff6 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -531,6 +531,19 @@ describe('executor', function() { done(); }); }); + + it('should preserve object prototypes', function(done) { + var config = simpleMiddlewareConfig( + 'routes', + // IMPORTANT we need more than one item to trigger the original issue + [/^\/foobar/, /^\/another/], + {}); + boot.execute(app, config); + + supertest(app).get('/foobar') + .expect(200) + .end(done); + }); }); describe('with component-config.json', function() { @@ -775,17 +788,26 @@ describe('executor', function() { }); -function simpleMiddlewareConfig(phase, params) { +function simpleMiddlewareConfig(phase, paths, params) { + if (params === undefined) { + params = paths; + paths = undefined; + } + + var config = { + phase: phase, + params: params + }; + + if (paths) config.paths = paths; + return someInstructions({ middleware: { phases: [phase], middleware: [ { sourceFile: path.join(__dirname, './fixtures/simple-middleware.js'), - config: { - phase: phase, - params: params - } + config: config, } ] }