about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--dispatcher.go6
-rw-r--r--route.go6
-rw-r--r--router_test.go16
3 files changed, 11 insertions, 17 deletions
diff --git a/dispatcher.go b/dispatcher.go
index 2e5f277..78c377f 100644
--- a/dispatcher.go
+++ b/dispatcher.go
@@ -1,7 +1,6 @@
 package mooh
 
 import (
-	"strings"
 	"errors"
 	"fmt"
 )
@@ -41,11 +40,6 @@ func (self *Dispatcher) AddRoute(path string, method string, code func(*Request)
 
 func (self *Dispatcher) Match(request Request) (*Route, error) {
 
-	// If the path starts with /, remove it
-	if request.Request.URL.Path[0] == '/' {
-		request.Request.URL.Path = strings.TrimLeft(request.Request.URL.Path, "/")
-	}
-
 	matches := []*Match{}
 
 	for _, r := range self.Routes {
diff --git a/route.go b/route.go
index b26ad5a..b5c932d 100644
--- a/route.go
+++ b/route.go
@@ -40,8 +40,6 @@ func (self *Route) Match(request Request) *Match {
 	}
 
 	components := strings.Split(request.Request.URL.Path, "/")
-
-	//fmt.Println(fmt.Sprintf("components are %s and %s, the lenght is %d, the length without opt is %d and total is %d", components, self.Components, len(components), self.LengthWithoutOptional, self.Length))
 	if len(components) < self.LengthWithoutOptional || len(components) > self.Length {
 		return nil
 	}
@@ -81,9 +79,7 @@ func MakeRoute(path string, method string, code func(*Request) (Response, error)
 	components := []string{}
 
 	for _, c := range strings.Split(path, "/") {
-		if c != "" {
-			components = append(components, c)
-		}
+		components = append(components, c)
 	}
 
 	reqComponents, optComponents := getNamedComponents(components)
diff --git a/router_test.go b/router_test.go
index 3a2d66d..95145b1 100644
--- a/router_test.go
+++ b/router_test.go
@@ -14,13 +14,17 @@ func testRoute(req *Request) (Response, error) {
 
 func TestBasic(t *testing.T) {
 	router := BuildDispatcher()
+	router.AddRoute("/", "GET", testRoute)
 	router.AddRoute("/blog/:year/:month/:day", "GET", testRoute)
 	router.AddRoute("/blog", "GET", testRoute)
 
-	if router.Routes[0].Path != "/blog/:year/:month/:day" {
+	if router.Routes[0].Path != "/" {
 		t.Fatal()
 	}
-	if router.Routes[1].Path != "/blog" {
+	if router.Routes[1].Path != "/blog/:year/:month/:day" {
+		t.Fatal()
+	}
+	if router.Routes[2].Path != "/blog" {
 		t.Fatal()
 	}
 }
@@ -31,9 +35,9 @@ func TestMatch(t *testing.T) {
 	router.AddRoute("/blog", "GET", testRoute)
 
 	pathToTests := []url.URL{
-		url.URL{Path: "blog"},
 		url.URL{Path: "/blog"},
-		url.URL{Path: "blog/2013/4/21"},
+		url.URL{Path: "/blog"},
+		url.URL{Path: "/blog/2013/4/21"},
 		url.URL{Path: "/blog/2013/21/4"},
 	}
 	for _, p := range pathToTests {
@@ -54,9 +58,9 @@ func TestMatchOptional(t *testing.T) {
 	router.AddRoute("/blog/:year/?:month", "GET", testRoute)
 
 	pathToTests := []url.URL{
-		url.URL{Path: "blog"},
 		url.URL{Path: "/blog"},
-		url.URL{Path: "blog/2013"},
+		url.URL{Path: "/blog"},
+		url.URL{Path: "/blog/2013"},
 		url.URL{Path: "/blog/2013/21"},
 	}
 	for _, p := range pathToTests {