Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug when route as "*" is final one #291

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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