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:
parent
24fbfbebf1
commit
1d27cf0e05
|
@ -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) {
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue