about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@lumberjaph.net>2013-04-21 16:37:36 -0700
committerFranck Cuny <franck@lumberjaph.net>2013-04-21 16:37:36 -0700
commit11d7b0a2a9b6cd2c26b9e3460d65685583a74dfa (patch)
treebc58756649feadef4d3d13a12db82bbbf34c346d
parentApply gofmt (diff)
downloadpath-router-11d7b0a2a9b6cd2c26b9e3460d65685583a74dfa.tar.gz
Normalize the name of captured components.
In the case of an optional components, the name is ":something".  We
need to normalize that name in order to be able to call directly
"something" when needed.
-rw-r--r--route.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/route.go b/route.go
index 38ff036..e7994f7 100644
--- a/route.go
+++ b/route.go
@@ -27,8 +27,15 @@ type Match struct {
 }
 
 var componentIsVariable = regexp.MustCompile("^:")
-var componentsIsOptional = regexp.MustCompile("^?:")
+var componentsIsOptional = regexp.MustCompile("^\\?:")
 var namedComponentsRegex = regexp.MustCompile("^:(.*)$")
+var convertComponent = regexp.MustCompile("^\\??:(.*)$")
+
+
+func (self *Route) convertComponentName(name string) string {
+	newName := convertComponent.FindStringSubmatch(name)
+	return newName[1]
+}
 
 func (self *Route) Match(request *http.Request) *Match {
 	methodMatch := false
@@ -55,7 +62,7 @@ func (self *Route) Match(request *http.Request) *Match {
 		p := components[i]
 
 		if componentIsVariable.MatchString(c) == true {
-			mapping[c] = p
+			mapping[self.convertComponentName(c)] = p
 		} else {
 			if p != c {
 				return nil