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

Strict should not allow a trailing slash #112

Closed
posva opened this issue Jun 30, 2017 · 3 comments
Closed

Strict should not allow a trailing slash #112

posva opened this issue Jun 30, 2017 · 3 comments
Labels

Comments

@posva
Copy link

posva commented Jun 30, 2017

Hello,

First, thanks a lot for creating path-to-repexp, we use it to handle paths in vue-router and it makes things pretty easy 🙂

When using strict: true, a path will only match with a trailing slash:

/foo -> /foo/ but no /foo

but this looks strange because I see no way to force a path not to have a trailing slash

? -> /foo but not /foo/

IMO, it would make more sense to allow the user to force the slash by simply appending it to the route: /foo/ -> /foo/ but not /foo

Now, I know this is a breaking channge but still wanted to know your thoughts about this because I couldn't find any previous issue about the topic

@MachinisteWeb
Copy link

MachinisteWeb commented Jun 30, 2017

Hi everyone!

I currently have this issue : vuejs/vue-router#1443 when I use vue-router that use path-to-regex as dependency.

A solution is to simply set pathToRegexOptions: { strict: true } to resolve this issue but what I see it's the reverse of what I want!

On my server, I set: /our-projects/ so

  • if I ask http://localhost:7777/our-projects/ there will respond 200 with « Project Template »
  • if I ask http://localhost:7777/our-projects there will respond 404 with « Error Template »

This is my initial cases:

  • standard case : I ask /our-projects/ -> Project Template (response server ok), hydratation Project Template (hydratation ok)
    normal-with-slash

  • issue case : I ask /our-projects -> Error Template (response server ok), hydratation Project Template (normal behavior of path-to-regex but issue for me)
    normal-without-slash

So I decide to use pathToRegexOptions: { strict: true } to solve the issue!

BUT I have two issues now !

  • real issue 1 : I ask /our-projects/ -> Project Template (response server ok), hydratation Error Template (nok issue should be Project )
    strict-with-slash
  • real issue 2 : I ask /our-projects -> Error Template (response server ok), hydratation Project Template (nok issue should be Error )
    strict-withou-slash

What I expected:

  • serveur Error -> hydratation Error for /our-projects and
  • serveur Project -> hydratation Project for /our-projects/

@blakeembrey
Copy link
Member

I don't follow this issue or understand the next comment, sorry. This is already how it works. See the test case:

path-to-regexp/test.ts

Lines 116 to 132 in e97122d

[
'/test',
{
strict: true
},
[
'/test'
],
[
['/test', ['/test']],
['/test/', null],
['/TEST', ['/TEST']]
],
[
[null, '/test']
]
],
. If I'm misunderstanding the request, please let me know.

@posva
Copy link
Author

posva commented Jun 30, 2017

oh, what the hell 😆
My bad, sorry for the noise, you're right, that's how it works right now

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

3 participants