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

case insensitive mode errors when installing valid routes that are not all lowercase #96

Closed
misterdjules opened this issue Oct 4, 2018 · 3 comments

Comments

@misterdjules
Copy link
Contributor

Here's a repro of the problem I'm seeing:

$ cat index.js 
const router = require('find-my-way')({
  caseSensitive: false
});

const routePatterns = [
  '/Foo/bar/:baz',
  '/Foo/baz/:bar',
];

routePatterns.forEach(function addRoute(routePattern) {
  console.log('adding route for pattern:', routePattern);

  router.on('GET', routePattern, (req, res, params) => {
    res.end('{"message":"hello world"}')
  });
});


$ npm ls find-my-way
test-find-my-way@1.0.0 /Users/jgilli/dev/test-find-my-way
└── find-my-way@1.15.3 

$ node --version
v6.14.3
$ node index.js 
adding route for pattern: /Foo/bar/:baz
adding route for pattern: /Foo/baz/:bar

assert.js:84
  throw new assert.AssertionError({
  ^
AssertionError: There is already a child with label ':'
    at Node.addChild (/Users/jgilli/dev/test-find-my-way/node_modules/find-my-way/node.js:57:3)
    at Router._insert (/Users/jgilli/dev/test-find-my-way/node_modules/find-my-way/index.js:249:19)
    at Router._on (/Users/jgilli/dev/test-find-my-way/node_modules/find-my-way/index.js:145:21)
    at Router.on (/Users/jgilli/dev/test-find-my-way/node_modules/find-my-way/index.js:58:8)
    at addRoute (/Users/jgilli/dev/test-find-my-way/index.js:13:10)
    at Array.forEach (native)
    at Object.<anonymous> (/Users/jgilli/dev/test-find-my-way/index.js:10:15)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
$ 

Changing those routes to be all lowercase seems to work around the problem. Not passing {caseSensitive: false} to the Router constructor also works around it.

@mcollina
Copy link
Collaborator

mcollina commented Oct 4, 2018

I bet I forgot a toLowerCase somewhere in #84. Would you like to send a PR to fix this?

@misterdjules
Copy link
Contributor Author

@mcollina I'll do that if I can find the time :)

@misterdjules
Copy link
Contributor Author

Done in #97. @mcollina Can you please take a look?

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

No branches or pull requests

2 participants