Skip to content

Commit

Permalink
fix #4: unesacpe parent directory before getting it's modification time
Browse files Browse the repository at this point in the history
  • Loading branch information
m3ng9i committed Oct 5, 2015
1 parent 585f201 commit 8318a6b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/dirlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,29 @@ func (this *RanServer) listDir(w http.ResponseWriter, c *context) (size int64, e
name += "/"
}
name = html.EscapeString(name)
url := url.URL{Path: name}
fileUrl:= url.URL{Path: name}

// write parent dir
if n == 0 && c.cleanPath != "/" {
parent := c.parent()

// unescape parent before get it's modification time
var parentUnescape string
parentUnescape, err = url.QueryUnescape(parent)
if err != nil {
return
}

var info os.FileInfo
info, err = os.Stat(filepath.Join(this.config.Root, parent))
info, err = os.Stat(filepath.Join(this.config.Root, parentUnescape))
if err != nil {
return
}

files = append(files, dirListFiles{Name:"[..]", Url:parent, ModTime:info.ModTime()})
}

files = append(files, dirListFiles{Name:name, Url:url.String(), Size:i.Size(), ModTime:i.ModTime()})
files = append(files, dirListFiles{Name:name, Url:fileUrl.String(), Size:i.Size(), ModTime:i.ModTime()})
}

data := dirList{ Title: title, Files: files}
Expand Down

0 comments on commit 8318a6b

Please sign in to comment.