Do not crash on invalid lines
This commit is contained in:
		
							parent
							
								
									f780314026
								
							
						
					
					
						commit
						107079411b
					
				
							
								
								
									
										10
									
								
								ftp.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								ftp.go
									
									
									
									
									
								
							@ -403,10 +403,12 @@ func parseDirListLine(line string) (*Entry, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Try various time formats that DIR might use, and stop when one works.
 | 
						// Try various time formats that DIR might use, and stop when one works.
 | 
				
			||||||
	for _, format := range dirTimeFormats {
 | 
						for _, format := range dirTimeFormats {
 | 
				
			||||||
		e.Time, err = time.Parse(format, line[:len(format)])
 | 
							if len(line) > len(format) {
 | 
				
			||||||
		if err == nil {
 | 
								e.Time, err = time.Parse(format, line[:len(format)])
 | 
				
			||||||
			line = line[len(format):]
 | 
								if err == nil {
 | 
				
			||||||
			break
 | 
									line = line[len(format):]
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
@ -58,6 +58,7 @@ var listTestsFail = []unsupportedLine{
 | 
				
			|||||||
	{"drwxr-xr-x    3 110      1002            3 Dec 02  209 pub", "Invalid year format in time string"},
 | 
						{"drwxr-xr-x    3 110      1002            3 Dec 02  209 pub", "Invalid year format in time string"},
 | 
				
			||||||
	{"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"},
 | 
						{"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"},
 | 
				
			||||||
	{"Zrwxrwxrwx   1 root     other          7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"},
 | 
						{"Zrwxrwxrwx   1 root     other          7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"},
 | 
				
			||||||
 | 
						{"total 1", "Unsupported LIST line"},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestParseValidListLine(t *testing.T) {
 | 
					func TestParseValidListLine(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user