From 23ec88ea5a560383b8b3ed7a5ef18045a36f05f9 Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Mon, 3 Nov 2014 11:29:51 -0800 Subject: [PATCH] Fix bug with string pattern matching with "." Previously, a route like "/:a.png" would match "/foo/bar/baz.png". This was incorrect, as all matches should be restricted to path segments (or smaller, as dictated by a break character). This bug was introduced in 1a390aba1c7c591e2c0c75be43eb830091b7d6f7. Fixes #75. --- web/pattern_test.go | 1 + web/string_pattern.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/web/pattern_test.go b/web/pattern_test.go index 7fb3c7a..8e8af29 100644 --- a/web/pattern_test.go +++ b/web/pattern_test.go @@ -124,6 +124,7 @@ var patternTests = []struct { pt("/a/cat", false, nil), pt("/a/cat/gif", false, nil), pt("/a/cat.", false, nil), + pt("/a/cat/dog.gif", false, nil), }}, // String prefix tests diff --git a/web/string_pattern.go b/web/string_pattern.go index 197c7c9..f68e044 100644 --- a/web/string_pattern.go +++ b/web/string_pattern.go @@ -45,7 +45,7 @@ func (s stringPattern) match(r *http.Request, c *C, dryrun bool) bool { m := 0 bc := s.breaks[i] for ; m < len(path); m++ { - if path[m] == bc { + if path[m] == bc || path[m] == '/' { break } }