aaronblohowiak / routes.js

a minimalist url-style routing library, extracted from connect
320 stars 48 forks source link

routes with N splats #1

Closed dominictarr closed 13 years ago

dominictarr commented 13 years ago

hey, suppose that I want to parse some thing like this:

"/aaa%2Fbb%2Fcc/uuuuu"

if I use a route like: "/*" i get:

{ params: {},
  splats: [ 'aaa/bb/cc/uuuuu' ],
  route: '/*',
  fn: [Function] }

I was kinda expecting

{ params: {},
  splats: [ 'aaa/bb/cc', 'uuuuu' ],
  route: '/*',
  fn: [Function] }

what do you think, is this reasonable behavior?

and can you point me to where I might start fixing this?

by the way, I want to use this to parse CLI commands. i'm passing them through:

argv._.map(function (u) {
  return '/'+ encodeURIComponent (u)
}).join('')
aaronblohowiak commented 13 years ago

a * is substituted for the regex (.+). when you have /aaa%Fbb%Fcc/uuuu, and the route '/'', it will match the *first part of the string (and as much of the string as possible) that fits \/(.+).

If i understood some more examples, I could give you better help.

route:'/:first/*' would evaluate to params: {first:"aaa%Fbb%Fcc"}, splats["uuuuu"].

If you generate more examples and what you want the desired behavior to be, I'll help you with the routing. For now, this is working as designed so I will close the issue.

dominictarr commented 13 years ago

thanks, that is helpful. so what is happening is the (.+) is catching everything, if I put more ///*/ after it would work, but what I'm trying to do is catch an arbitrary number url splats. but routes does not work recursively.

basicially I wanted to /split/every/slash-separated/section/into/splats

{
 splats: ["split","every","slash-separated","section","into","splats"]
}

but I can see now that will not fit well into the routes api.

thanks!

aaronblohowiak commented 13 years ago

ah, yes. this would be better with just using '/split/every/slash-separated/section/into/splats'.split("/")

dominictarr commented 13 years ago

yeah, I'm looking for a router that makes sense on the commandline and on the url, but you can do:


ls *

on the cli, which will be expanded by the shell, and ls will see a list or args, but you never get urls like that...