koajs / router

Router middleware for Koa. Maintained by @forwardemail and @ladjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-router v9 not supporting wildcard anymore

zhonggithub opened this issue · comments

commented

router.get('/*', async (ctx) => {
ctx.type = 'html';
ctx.body = fs.createReadStream(${__dirname}/../public/index.html);
});

same issuse ZijianHe/koa-router#527 (comment)
the error where happing like this:

/Users/zz/workspace/zBase/z-app/node_modules/path-to-regexp/dist/index.js:113
throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
^

TypeError: Unexpected MODIFIER at 1, expected END
at mustConsume (/Users/zz/workspace/zBase/z-app/node_modules/path-to-regexp/src/index.ts:157:11)
at parse (/Users/zz/workspace/zBase/z-app/node_modules/path-to-regexp/src/index.ts:228:5)
at stringToRegexp (/Users/zz/workspace/zBase/z-app/node_modules/path-to-regexp/src/index.ts:494:25)
at pathToRegexp (/Users/zz/workspace/zBase/z-app/node_modules/path-to-regexp/src/index.ts:616:10)
at new Layer (/Users/zz/workspace/zBase/z-app/node_modules/@koa/router/lib/layer.js:44:17)
at Router.register (/Users/zz/workspace/zBase/z-app/node_modules/@koa/router/lib/router.js:561:17)
at Router.get (/Users/zz/workspace/zBase/z-app/node_modules/@koa/router/lib/router.js:199:12)
at Object. (/Users/zz/workspace/zBase/z-app/src/router/index.js:42:8)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Module._compile (/Users/zz/workspace/zBase/z-app/node_modules/pirates/lib/index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)

This is a major breaking change (1.x.x to 6.1.0), and it was badly documented.
You can solve this by replacing * with (.*).

Keep in mind the code sample you provided is vulnerable. Don't create a read stream to an user-provided file hahaha (eg ../../../../../etc/passwd%00)

This is a major breaking change (1.x.x to 6.1.0), and it was badly documented.
You can solve this by replacing * with (.*).

Keep in mind the code sample you provided is vulnerable. Don't create a read stream to an user-provided file hahaha (eg ../../../../../etc/passwd%00)

Thanks @tabarra ! Worked like a charm. Yes I agree with documenting this breaking change as it look me a bit to finally figure out the issue.

This still isn't documented on the API Reference. It takes but a minute to add a few words folks.

PR welcome!

Clean up the existing PRs and I'd consider it. Stale PRs in a project is not exactly welcoming to more contributions, especially from folks who are themselves extremely active maintainers of popular open source projects.

As stated, I will accept a PR if you open one and ping me after. My email is niftylettuce@gmail.com as well if you want to ping by email when PR is done. If the PR is only a few minutes to open then you should have no problem, thank you.