Trim trailing whitespace from list commands
Listing a current directory (when the path argument is empty) would send the command "LIST " with trailing whitespace to FTP resulting in 500 errors with Solaris FTP server. This patch fixes that.
This commit is contained in:
parent
9aae4d1511
commit
24897db640
@ -7,6 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -300,3 +302,20 @@ func TestMissingFolderDeleteDirRecur(t *testing.T) {
|
|||||||
// Wait for the connection to close
|
// Wait for the connection to close
|
||||||
mock.Wait()
|
mock.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListCurrentDir(t *testing.T) {
|
||||||
|
mock, c := openConn(t, "127.0.0.1")
|
||||||
|
|
||||||
|
_, err := c.List("")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "LIST", mock.lastFull, "LIST must not have a trailing whitespace")
|
||||||
|
|
||||||
|
_, err = c.NameList("")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "NLST", mock.lastFull, "NLST must not have a trailing whitespace")
|
||||||
|
|
||||||
|
err = c.Quit()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
mock.Wait()
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ type ftpMock struct {
|
|||||||
listener *net.TCPListener
|
listener *net.TCPListener
|
||||||
proto *textproto.Conn
|
proto *textproto.Conn
|
||||||
commands []string // list of received commands
|
commands []string // list of received commands
|
||||||
|
lastFull string // full last command
|
||||||
rest int
|
rest int
|
||||||
fileCont *bytes.Buffer
|
fileCont *bytes.Buffer
|
||||||
dataConn *mockDataConn
|
dataConn *mockDataConn
|
||||||
@ -66,6 +67,7 @@ func (mock *ftpMock) listen(t *testing.T) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
fullCommand, _ := mock.proto.ReadLine()
|
fullCommand, _ := mock.proto.ReadLine()
|
||||||
|
mock.lastFull = fullCommand
|
||||||
|
|
||||||
cmdParts := strings.Split(fullCommand, " ")
|
cmdParts := strings.Split(fullCommand, " ")
|
||||||
|
|
||||||
|
12
ftp.go
12
ftp.go
@ -539,7 +539,11 @@ func (c *ServerConn) cmdDataConnFrom(offset uint64, format string, args ...inter
|
|||||||
|
|
||||||
// NameList issues an NLST FTP command.
|
// NameList issues an NLST FTP command.
|
||||||
func (c *ServerConn) NameList(path string) (entries []string, err error) {
|
func (c *ServerConn) NameList(path string) (entries []string, err error) {
|
||||||
conn, err := c.cmdDataConnFrom(0, "NLST %s", path)
|
space := " "
|
||||||
|
if path == "" {
|
||||||
|
space = ""
|
||||||
|
}
|
||||||
|
conn, err := c.cmdDataConnFrom(0, "NLST%s%s", space, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -570,7 +574,11 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
|
|||||||
parser = parseListLine
|
parser = parseListLine
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := c.cmdDataConnFrom(0, "%s %s", cmd, path)
|
space := " "
|
||||||
|
if path == "" {
|
||||||
|
space = ""
|
||||||
|
}
|
||||||
|
conn, err := c.cmdDataConnFrom(0, "%s%s%s", cmd, space, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user