Skip to content

Commit

Permalink
Merge pull request #208 from finagle/fix-207
Browse files Browse the repository at this point in the history
Clear priority of routers
  • Loading branch information
vkostyukov committed Feb 26, 2015
2 parents 23cecfa + b403a4c commit 49edd59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/io/finch/route/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ trait RouterN[+A] { self =>
def orElse[B >: A](that: RouterN[B]): RouterN[B] = new RouterN[B] {
def apply(route: Route): Option[(Route, B)] = (self(route), that(route)) match {
case (aa @ Some((a, _)), bb @ Some((b, _))) =>
if (a.length < b.length) aa else bb
if (a.length <= b.length) aa else bb
case (a, b) => a orElse b
}

Expand Down Expand Up @@ -185,7 +185,7 @@ trait Router0 { self =>
def orElse(that: Router0): Router0 = new Router0 {
def apply(route: Route): Option[Route] = (self(route), that(route)) match {
case (aa @ Some(a), bb @ Some(b)) =>
if (a.length < b.length) aa else bb
if (a.length <= b.length) aa else bb
case (a, b) => a orElse b
}

Expand Down
12 changes: 12 additions & 0 deletions core/src/test/scala/io/finch/route/RouterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,16 @@ class RouterSpec extends FlatSpec with Matchers {
r3(emptyRoute) shouldBe None
r4(emptyRoute) shouldBe None
}

it should "use the first router if both eats the same number of tokens" in {
val r =
Get /> "root" |
Get / "foo" /> "foo"

val route1 = List(MethodToken(Method.Get))
val route2 = List(MethodToken(Method.Get), PathToken("foo"))

r(route1) shouldBe Some((Nil, "root"))
r(route2) shouldBe Some((Nil, "foo"))
}
}

0 comments on commit 49edd59

Please sign in to comment.