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

Impossible to compile to + and * #58

Closed
klimashkin opened this issue Jun 30, 2015 · 3 comments
Closed

Impossible to compile to + and * #58

klimashkin opened this issue Jun 30, 2015 · 3 comments

Comments

@klimashkin
Copy link

var toPath = pathToRegexp.compile('/goods/:splat+')
var result = toPath({ splat: '1/all' })  //error

var toPath = pathToRegexp.compile('/goods/:splat(.+)')
var result = toPath({ splat: '1/all' })
console.log(result) //=> "/goods/1%2Fall"
@blakeembrey
Copy link
Member

I guess this isn't 100% right now. The issue is that it shouldn't have a slash in the path. If you want a slash with that, you need to pass an array like { splat: [1, 'all'] }.

However, that begs the question of whether encoding it as I currently do is the correct behaviour since there would be no way to input an encoded slash right now. Perhaps either encoding it before validation or removing encoding?

@IsaiahJTurner
Copy link

I think this is the same issue I am experiencing but I'm not sure. I want to define a route like /:postType(video|audio|text)?+* that will match /video, /audio, and /video+someTextString. Basically, treating the plus sign as an alias. The closest working alternative I've found is ``/:postType(video|audio|text)?\+*` but for some reason that won't match URLs that do not contain a plus sign.

@blakeembrey
Copy link
Member

@IsaiahJTurner It looks like a different issue. Plus signs that are by themselves have no semantic effect, it's just a plus sign. The match you are doing results with /^(?:\/(video|audio|test))?\+(.*)(?:\/(?=$))?$/i. Notice the plus sign that must be matched in the middle. Not sure what the difference between your two examples are though, they should be treated exactly the same.

I don't have a perfect solution for you with this. Either you can add a plus sign as video+|audio+|text+, or you could use an array of matches (probably preferable) like ['/:postType(video|audio|text)\+*', '/*'].

blakeembrey added a commit that referenced this issue Aug 17, 2015
MUDev1994 pushed a commit to MUDev1994/path-to-regexp that referenced this issue May 26, 2023
MUDev1994 pushed a commit to MUDev1994/path-to-regexp that referenced this issue May 26, 2023
Forces the behavior to be consistent with path matching logic which does match against encoded paths. This is essentially the reverse. 

Closes pillarjs#58
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

3 participants