Skip to content

Commit

Permalink
Merge pull request #291 from namecheap/respectIndependentRouteAsStar
Browse files Browse the repository at this point in the history
fix: bug when route as "*" is final one
  • Loading branch information
Volodymyr Makukha authored May 5, 2021
2 parents f826688 + 324c9ea commit f5facce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ilc/common/router/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = class Router {
let routeExp;

if (v.route === '*') {
routeExp = new RegExp(`(.*)`);
routeExp = new RegExp(`(\/).*`);
} else if (v.route === '/') {
routeExp = new RegExp(`^(/)$`);
} else if (v.route.match(/\/\*$/) !== null) {
Expand Down
23 changes: 23 additions & 0 deletions ilc/common/router/Router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ describe('router', () => {
});
});

it('should return matched route with correct basePath if exists only route="*" as final point', () => {
const independentRouteStar = registryConfig.routes.find(n => n.route === '*');

const router = new Router({
...registryConfig,
routes: [{
...independentRouteStar,
next: false,
}],
});
const reqUrl = '/hero/apps?prop=value';

const result = {
...independentRouteStar,
reqUrl,
specialRole: null,
basePath: '/',
};
delete result.next;

chai.expect(router.match(reqUrl)).to.be.eql(result);
});

it('should return 404 route when a router does not match any route', () => {
const router = new Router(registryConfig);
const reqUrl = '/nonexistent?prop=value';
Expand Down

0 comments on commit f5facce

Please sign in to comment.