Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
path.Clean update args (paths)
Browse files Browse the repository at this point in the history
This is a better alternative as it cleans all possible crazy input.

/cc @kr
  • Loading branch information
Edward Muller committed Nov 6, 2015
1 parent 218402f commit 0a8bd86
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v26 2015/11/05

* Better fix for the issue fixed in v25: All update paths are now path.Clean()'d

# v25 2015/11/05

* `godep update package/` == `godep update package`. Fixes #313
Expand Down
1 change: 0 additions & 1 deletion match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestMatchPattern(t *testing.T) {
{"net/...", "net", true},
{"net/...", "net/http", true},
{"net/...", "not/http", false},
{"net/", "net", true},
}
for _, test := range cases {
ok := matchPattern(test.pat)(test.path)
Expand Down
7 changes: 3 additions & 4 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go/parser"
"go/token"
"log"
"path"
"path/filepath"
"regexp"
"strconv"
Expand Down Expand Up @@ -44,6 +45,7 @@ func update(args []string) error {
return err
}
for _, arg := range args {
arg := path.Clean(arg)
any := markMatches(arg, g.Deps)
if !any {
log.Println("not in manifest:", arg)
Expand Down Expand Up @@ -136,10 +138,7 @@ func matchPattern(pattern string) func(name string) bool {
re := regexp.QuoteMeta(pattern)
re = strings.Replace(re, `\.\.\.`, `.*`, -1)
// Special case: foo/... matches foo too.
switch {
case strings.HasSuffix(re, `/`):
re = re[:len(re)-len(`/`)] + `(/)?`
case strings.HasSuffix(re, `/.*`):
if strings.HasSuffix(re, `/.*`) {
re = re[:len(re)-len(`/.*`)] + `(/.*)?`
}
reg := regexp.MustCompile(`^` + re + `$`)
Expand Down
35 changes: 35 additions & 0 deletions update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,41 @@ func TestUpdate(t *testing.T) {
},
},
},
{ // simple case, update one dependency, trailing slash
cwd: "C",
args: []string{"D/"},
start: []*node{
{
"D",
"",
[]*node{
{"main.go", pkg("D") + decl("D1"), nil},
{"+git", "D1", nil},
{"main.go", pkg("D") + decl("D2"), nil},
{"+git", "D2", nil},
},
},
{
"C",
"",
[]*node{
{"main.go", pkg("main", "D"), nil},
{"Godeps/Godeps.json", godeps("C", "D", "D1"), nil},
{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
{"+git", "", nil},
},
},
},
want: []*node{
{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D2"), nil},
},
wdep: Godeps{
ImportPath: "C",
Deps: []Dependency{
{ImportPath: "D", Comment: "D2"},
},
},
},
{ // update one dependency, keep other one, no rewrite
cwd: "C",
args: []string{"D"},
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const version = 25
const version = 26

0 comments on commit 0a8bd86

Please sign in to comment.