Merge pull request #159 from strongloop/fix/interpolate-regexp
executor: preserve RegExps in middleware paths
This commit is contained in:
commit
5f0175afbf
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue