Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved URL Parsing #111

Merged
merged 20 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/urfave/cli/v2"
"github.com/kballard/go-shellquote"

"github.com/peak/s5cmd/parallel"
)
Expand Down Expand Up @@ -86,7 +87,11 @@ var runCommand = &cli.Command{
continue
}

fields := strings.Fields(line)
fields, err := shellquote.Split(line)
if err != nil {
return err
}

if len(fields) == 0 {
continue
}
Expand Down
31 changes: 31 additions & 0 deletions e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,34 @@ func TestRunWildcardCountGreaterEqualThanWorkerCount(t *testing.T) {

assertLines(t, result.Stderr(), map[int]compareFunc{})
}

func TestRunSpecialCharactersInPrefix(t *testing.T) {
t.Parallel()

bucket := s3BucketFromTestName(t)
sourceFileName := `special-chars_!@#$%^&_()_+{[_%5Cäè| __;'_,_._-中文 =/_!@#$%^&_()_+{[_%5Cäè| __;'_,_._-中文 =image.jpg`
targetFilePath := `./image.jpg`

s3client, s5cmd, cleanup := setup(t)
defer cleanup()

createBucket(t, s3client, bucket)
putFile(t, s3client, bucket, sourceFileName, "content")

content := []string{
`cp "s3://` + bucket + `/` + sourceFileName + `" ` + targetFilePath,
}
file := fs.NewFile(t, "prefix", fs.WithContent(strings.Join(content, "\n")))
defer file.Remove()

cmd := s5cmd("run", file.Path())
cmd.Timeout = time.Second
result := icmd.RunCmd(cmd)
result.Assert(t, icmd.Success)

assertLines(t, result.Stdout(), map[int]compareFunc{
0: equals(`cp s3://%v/%v %v`, bucket, sourceFileName, targetFilePath),
}, sortInput(true))

assertLines(t, result.Stderr(), map[int]compareFunc{})
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/johannesboyne/gofakes3 v0.0.0-20191228161223-9aee1c78a252
github.com/karrick/godirwalk v1.15.3
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kr/pretty v0.2.0 // indirect
github.com/posener/complete v1.2.3
github.com/stretchr/testify v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/karrick/godirwalk v1.15.3 h1:0a2pXOgtB16CqIqXTiT7+K9L73f74n/aNQUnH6Ortew=
github.com/karrick/godirwalk v1.15.3/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
2 changes: 1 addition & 1 deletion storage/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (u *URL) setPrefixAndFilter() error {
filterRegex = strings.Replace(filterRegex, "\\?", ".", -1)
filterRegex = strings.Replace(filterRegex, "\\*", ".*?", -1)
}
filterRegex = u.Prefix + filterRegex
filterRegex = regexp.QuoteMeta(u.Prefix) + filterRegex
r, err := regexp.Compile("^" + filterRegex + "$")
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions vendor/github.com/kballard/go-shellquote/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/kballard/go-shellquote/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/kballard/go-shellquote/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions vendor/github.com/kballard/go-shellquote/quote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading