izqui / Taylor

A lightweight library for writing HTTP web servers with Swift
MIT License
926 stars 79 forks source link

Implement wildcard (*) #31

Closed Danappelxx closed 8 years ago

Danappelxx commented 8 years ago

Needs review.

Valid statements:

server.get("/*", ...)
server.get("/*/something", ...)
server.get("/something/*/", ...)

and pretty much anything else involving the wildcard character *.

I've done some testing on my own but I'm not convinced that it's completely bug-free.

kevinup7 commented 8 years ago

It looks like it's not handling wildcards with more than one component correctly.

server.get("/something/*", ...)

will match: /something/else but not: /something/else/entirely

The problem seems to be here:

guard self.components.count == request.pathComponents.count else {
    return false
}

After thinking about it, the route path can never have more components than the request URL, but the request URL can have more components than the route path if there are wildcard paths involved.

Danappelxx commented 8 years ago

Right - I figured that would make more sense anyway - /*/* does work though. Maybe use /** where you want it to be recursive?

Danappelxx commented 8 years ago

I'm going to merge this since its a trivial change that doesn't break anything. Regarding @kevinup7's note - I think it makes more sense the way it is implemented right now anyway. /something/* should not match /something/else/entirely, because that would mean that /something/*/entirely matches something/else/else/else/else/else/entirely, which is (in my opinion) incorrect. If we were to implement this sort of behavior, it should be with the double-globstar **, not the single kind *.