Merge pull request #159 from strongloop/fix/interpolate-regexp

executor: preserve RegExps in middleware paths
This commit is contained in:
Miroslav Bajtoš 2015-11-24 18:53:17 +01:00
commit 5f0175afbf
2 changed files with 31 additions and 5 deletions

View File

@ -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) {

View File

@ -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,
}
]
}