-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
by steview.woodcock:
Desc: The textproto package multiline support does not correctly deal with the FTP multi-line spec. This was refered to in a code review: http://golang.org/cl/1892052: -------------- Description net/textproto: Handle multi-line responses This is required for FTP and SMTP; maybe others. ------------ Specifically, the issue is the reader expects every line to have the same code prefix which is not the case for FTP, as intermediate lines can start with spaces or other text to provide extra info. This breaks the parsing and causes it to report a mismatched status code sequence. From http://www.ietf.org/rfc/rfc959.txt (page 36) ---------------------------- Thus the format for multi-line replies is that the first line will begin with the exact required reply code, followed immediately by a Hyphen, "-" (also known as Minus), followed by text. The last line will begin with the same code, followed immediately by Space <SP>, optionally some text, and the Telnet end-of-line code. For example: 123-First line Second line 234 A line beginning with numbers 123 The last line The user-process then simply needs to search for the second occurrence of the same reply code, followed by <SP> (Space), at the beginning of a line, and ignore all intermediary lines. If an intermediary line begins with a 3-digit number, the Server must pad the front to avoid confusion. ------------------------- What steps will reproduce the problem? 1.run the following test: import ( "testing" "fmt" "net/textproto" "bufio" "strings" ) func reader(s string) *textproto.Reader { return textproto.NewReader(bufio.NewReader(strings.NewReader(s))) } func TestReader(t *testing.T) { reader:= reader("230-Anonymous access granted, restrictions apply\n Please read the file README.txt\n230 it was last modified on Tue Aug 15 14:29:31 2000 - 4033 days ago") code, msg, err :=reader.ReadResponse(230) if err !=nil { t.Errorf("#%d: error, fail %q \n", code, err) }else{ fmt.Printf("Response: %d %s \n",code,msg) } } which fails with: testing : --- FAIL: ftp.TestReader (0.00 seconds) #230: error, fail "status code mismatch: 230, 0" FAIL What is the expected output? should print Response: 230 Anonymous access granted, restrictions apply What do you see instead? testing : --- FAIL: ftp.TestReader (0.00 seconds) #230: error, fail "status code mismatch: 230, 0" FAIL Which compiler are you using (5g, 6g, 8g, gccgo)? 6g Which operating system are you using? OSX Which revision are you using? (hg identify) release/release.r59 Please provide any additional information below.