executor: preserve RegExps in middleware paths

Fix interpolateVariables() to skip objects with a non-default
constructor, for example RegExp or Date.
This commit is contained in:
Miroslav Bajtoš 2015-11-04 15:47:55 +01:00
parent 24fbfbebf1
commit 1d27cf0e05
2 changed files with 31 additions and 5 deletions

View File

@ -354,6 +354,10 @@ function getUpdatedConfigObject(app, config) {
if (Array.isArray(config)) if (Array.isArray(config))
return config.map(interpolateVariables); return config.map(interpolateVariables);
// Not a plain object. Examples: RegExp, Date,
if (!config.constructor || config.constructor !== Object)
return config;
// recurse into object props // recurse into object props
var interpolated = {}; var interpolated = {};
Object.keys(config).forEach(function(configKey) { Object.keys(config).forEach(function(configKey) {

View File

@ -531,6 +531,19 @@ describe('executor', function() {
done(); 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() { 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({ return someInstructions({
middleware: { middleware: {
phases: [phase], phases: [phase],
middleware: [ middleware: [
{ {
sourceFile: path.join(__dirname, './fixtures/simple-middleware.js'), sourceFile: path.join(__dirname, './fixtures/simple-middleware.js'),
config: { config: config,
phase: phase,
params: params
}
} }
] ]
} }