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

[147] Ensure path sanity checks provide clear errors during registrat… #154

Closed
wants to merge 0 commits into from

Conversation

peterver
Copy link
Contributor

…ion checks

Checklist

  • [v] I have ensured my pull request is not behind the main or master branch of the original repository.
  • [v] I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • [v] I have written a commit message that passes commitlint linting.
  • [v] I have ensured that my code changes pass linting tests.
  • [v] I have ensured that my code changes pass unit tests.
  • [v] I have described my pull request and the reasons for code changes along with context if necessary.

@peterver
Copy link
Contributor Author

this is an adjusted version of #147 with unit tests added for correctness

@etroynov
Copy link
Contributor

@peterver hi you can change [v] -> [x] and list will be look like here:
#153

@etroynov
Copy link
Contributor

@wengeezhang could you check it?

@etroynov
Copy link
Contributor

@peterver I suppose it's not good approach make PR from master to master, maybe you should create separate branch for it.

lib/router.js Outdated
});
// Sanity check to ensure we have a viable path candidate (eg: string|regex|non-empty array)
if (
typeof path !== "string" &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In project usually use single quotes not double

lib/router.js Outdated
this.register(path, methods, middleware, { name });
// Sanity check to ensure we have a viable path candidate (eg: string|regex|non-empty array)
if (
typeof path !== "string" &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In project usually use single quotes not double

@@ -993,7 +993,30 @@ describe('Router', function () {
done();
});
});

it ('correctly returns an error when not passed a path for verb-specific registration (gh-148)', function () {
const app = new Koa();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

In this test you have some unused variables, you can fix it like this:

const router = new Router();

 try {
  router.get(function () {});
 } catch (e) {
   expect(e.message).to.be('You have to provide a path when adding a get handler');
 }


it ('correctly returns an error when not passed a path for "all" registration (gh-148)', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test you have some unused variables, you can fix it like this:

const router = new Router();

try {
    router.all(function () {});
} catch (e) {
    expect(e.message).to.be('You have to provide a path when adding an all handler');
}

@peterver
Copy link
Contributor Author

@peterver I suppose it's not good approach make PR from master to master, maybe you should create separate branch for it.

Apologies, first contribution here and want to get going :D I'm used to working in a git-flow approach (develop/master) and wasn't sure about the proper practice here :). Will adhere for future PR's thanks!

@peterver
Copy link
Contributor Author

peterver commented Jun 30, 2022

@etroynov I've opened a new PR #155 with all of the above adjustment requests included :). PS: there were 1 or 2 additional uses of double quote over single quote, I've gone ahead and changed those as well, thanks for ensuring code style :)

@titanism
Copy link
Contributor

titanism commented Jul 4, 2022

We have just published @koajs/router v11.0.0 which resolves this issue. This is mirrored to koa-router as well.

https://github.com/koajs/router/releases/tag/v11.0.0

This project is maintained by Forward Email and Lad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants