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

Support for ? in paths #214

Closed
wants to merge 1 commit into from
Closed

Support for ? in paths #214

wants to merge 1 commit into from

Conversation

mjackson
Copy link
Member

[changed] * in paths no longer matches .
[added] Support for arrays in query strings

Fixes #142

it('returns an object with the params', function () {
expect(Path.extractParams(pattern, '/archive')).toEqual({ name: undefined });
expect(Path.extractParams(pattern, '/archive/')).toEqual({ name: undefined });
expect(Path.extractParams(pattern, '/archive/foo')).toEqual({ name: 'foo' });
Copy link
Contributor

Choose a reason for hiding this comment

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

what about /archivefoo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good catch. Added.

case '(':
case ')':
case '^':
case '$':
Copy link
Contributor

Choose a reason for hiding this comment

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

are any of these chars even valid in a URL?

edit: well, I suppose . is…

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, all except for ^ which should be URL-encoded. See RFC 3986. The thinking here was mainly to prevent them from appearing in the source of the RegExp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I just meant that you wouldn't even write those as part of your URL patterns if URLs can't look like that. I could imagine it being valuable to support regex patterns in the future but this seems good for now. Do you also want to do []+|{}\ which are also regexp special chars?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I should probably add those too. + will need some special handling because that's how we encode spaces in URLs.

@mjackson
Copy link
Member Author

@spicyj All special RegExp chars are now escaped properly.

This was referenced Aug 27, 2014
@mjackson mjackson changed the title [added] Support for ? in paths Support for ? in paths Aug 27, 2014

describe('when a pattern has multiple splats', function () {
it('returns the correct path', function () {
expect(Path.injectParams('/a/*/c/*', { splat: [ 'b', 'd' ] })).toEqual('/a/b/c/d');
Copy link
Member

Choose a reason for hiding this comment

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

When would I use splats instead of params?

@ryanflorence
Copy link
Member

We have an app right now that uses the splat to match an arbitrary file path in a file browsing app.

<Route name="file" path="/file/*" />

This will match things like /file/foo/bar/baz.qux.js giving us foo/bar/baz.qux.js as splat. I can't figure a way to still do this with these changes.

Issues are:

  • allowing / to be matched w/o being a separator
  • matching an arbitrary number of .

<Route path="file/**"/> <Route path="file/..."/> anyone?

[changed] :param no longer matches .
[added] Support for arrays in query strings

Fixes #142
@mjackson
Copy link
Member Author

ok, so now that I've gotten some sleep and am thinking about this clearly, here's what's going on:

  1. :param no longer matches .
  2. * still works as it did before
  3. ? means "match the previous thing 0 or 1 time"

So, all of the following paths work as you'd expect:

/files/*
/files/:name.:ext
/files/:name.?:ext?
/files/?

Also, we should point out in the docs that * is not greedy. So it won't match a ., /, or anything else that follows it. This means that you can do stuff like:

/files/*.jpg
/files/*/pics/*

@ryanflorence
Copy link
Member

closed by d5bd656

@ryanflorence
Copy link
Member

👍

I reworded the commit because the changelog only looks at subjects, not the commit message body. I wanted a message that says "hey ... lots changed"

@mjackson mjackson deleted the path-matching branch August 29, 2014 21:57
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More powerful/flexible path matching
3 participants