summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2010-02-25 09:15:52 -0800
committerKevin Ballard <kevin@sb.org>2010-02-25 09:15:52 -0800
commitb36f5ea9726368ea38ae00f88e61710321c9f49f (patch)
tree2a56368451a0215c21fdb70d72555488add483bf /src
parentb5c34b76a8f0b7f161b38ba7c1161659c9d6a805 (diff)
downloadgolang-b36f5ea9726368ea38ae00f88e61710321c9f49f.tar.gz
path: Fix bug in Match with non-greedy stars
path.Match() errors out when testing "*x" against "xxx" because it matches the star non-greedily. Ensure that the last chunk consumes the rest of the name. R=r, rsc CC=golang-dev http://codereview.appspot.com/223050 Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/pkg/path/match.go9
-rw-r--r--src/pkg/path/match_test.go1
2 files changed, 9 insertions, 1 deletions
diff --git a/src/pkg/path/match.go b/src/pkg/path/match.go
index 4e42b6a10..e3cf08cae 100644
--- a/src/pkg/path/match.go
+++ b/src/pkg/path/match.go
@@ -41,7 +41,10 @@ Pattern:
}
// Look for match at current position.
t, ok, err := matchChunk(chunk, name)
- if ok {
+ // if we're the last chunk, make sure we've exhausted the name
+ // otherwise we'll give a false result even if we could still match
+ // using the star
+ if ok && (len(t) == 0 || len(pattern) > 0) {
name = t
continue
}
@@ -54,6 +57,10 @@ Pattern:
for i := 0; i < len(name) && name[i] != '/'; i++ {
t, ok, err := matchChunk(chunk, name[i+1:])
if ok {
+ // if we're the last chunk, make sure we exhausted the name
+ if len(pattern) == 0 && len(t) > 0 {
+ continue
+ }
name = t
continue Pattern
}
diff --git a/src/pkg/path/match_test.go b/src/pkg/path/match_test.go
index d3cd088f1..c02384f92 100644
--- a/src/pkg/path/match_test.go
+++ b/src/pkg/path/match_test.go
@@ -64,6 +64,7 @@ var matchTests = []MatchTest{
MatchTest{"[-x]", "a", false, ErrBadPattern},
MatchTest{"\\", "a", false, ErrBadPattern},
MatchTest{"[a-b-c]", "a", false, ErrBadPattern},
+ MatchTest{"*x", "xxx", true, nil},
}
func TestMatch(t *testing.T) {