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

Double slash before Router (router//route) #4427

Closed
checnev opened this issue Oct 9, 2020 · 5 comments
Closed

Double slash before Router (router//route) #4427

checnev opened this issue Oct 9, 2020 · 5 comments
Labels

Comments

@checnev
Copy link

checnev commented Oct 9, 2020

Hello, when i assign a router to the route, then there is access to routes with a double slash at the beginning.

example:

const express = require('express');
const app = express();
const port = 3000;

const router = express.Router({ strict: true }); // i've tried without strict mode
router.get('/test', (req, res) => {
  res.send('test');
});

app.use('/user', router);

app.listen(port, () => console.log(`app listening on port ${port}!`))

The router is supposed to run on the /user/test route, but the /user//test also works.

Environment:

"node": 14.3.0
"express": 4.17.1
@varmagtm
Copy link

varmagtm commented Oct 9, 2020

Consecutive multiple path separators (the forward slash, in your case) in the URLs do not have any significance in the modern-day operating systems. But it is advised not to use like so.

Please refer to the Stackoverflow question here - https://stackoverflow.com/questions/10161177/url-with-multiple-forward-slashes-does-it-break-anything.

@checnev
Copy link
Author

checnev commented Oct 15, 2020

Consecutive multiple path separators (the forward slash, in your case) in the URLs do not have any significance in the modern-day operating systems. But it is advised not to use like so.

Please refer to the Stackoverflow question here - https://stackoverflow.com/questions/10161177/url-with-multiple-forward-slashes-does-it-break-anything.

yes, but it's not expected behavior, I'm interested in how to disallow double slashes

@rodion-arr
Copy link
Contributor

@checnev usually this situation is not good for SEO purposes, I assume it's possible to write a middleware to detect this case and return 301 redirect to correct URI.

@RahulBansal123
Copy link

Consecutive multiple path separators (the forward slash, in your case) in the URLs do not have any significance in the modern-day operating systems. But it is advised not to use like so.
Please refer to the Stackoverflow question here - https://stackoverflow.com/questions/10161177/url-with-multiple-forward-slashes-does-it-break-anything.

yes, but it's not expected behavior, I'm interested in how to disallow double slashes

But is it is advised to handle it by writing a middleware as double slashes may cause problems while caching.

@rodion-arr
Copy link
Contributor

I'm closing this as I truly believe in case this behaviour causes issues - it can be easily handled on middleware level. Please feel free to reopen in case I'm mistaken and we will try to raise it further to maintainers.

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

No branches or pull requests

4 participants