fix manifest path matching slashes issue

This commit is contained in:
zelig 2015-05-29 14:56:57 +01:00
parent 0501ff41d0
commit 38d1bdf688
2 changed files with 22 additions and 5 deletions

View file

@ -93,6 +93,9 @@ func (self *Api) Stop() {
func (self *Api) Get(bzzpath string) (content []byte, mimeType string, status int, size int, err error) {
var reader SectionReader
reader, mimeType, status, err = self.getPath("/" + bzzpath)
if err != nil {
return
}
content = make([]byte, reader.Size())
size, err = reader.Read(content)
if err == io.EOF {

View file

@ -1,13 +1,18 @@
package bzz
import (
// "fmt"
// "fmt"
"regexp"
)
const (
manifestType = "application/bzz-manifest+json"
)
var (
leadingSlashes = regexp.MustCompile("^/+")
)
type manifest struct {
Entries []*manifestEntry `json:"entries"`
}
@ -21,12 +26,21 @@ type manifestEntry struct {
func (self *manifest) getEntry(path string) (entry *manifestEntry, pos int) {
for _, entry = range self.Entries {
pos = len(entry.Path)
if len(path) >= pos && path[:pos] == entry.Path {
entryPath := leadingSlashes.ReplaceAllString(entry.Path, "")
pos = len(entryPath)
if len(path) >= pos && path[:pos] == entryPath {
var n int
if len(path) > pos {
chopped := leadingSlashes.ReplaceAllString(path[pos:], "")
n = len(path) - pos - len(chopped)
}
if n > 0 || pos == 0 || path[pos-1] == '/' {
pos += n
dpaLogger.Debugf("Swarm: '%s' matches '%s'.", path, entry.Path)
return
}
}
}
entry = nil
dpaLogger.Debugf("Path '%s' on manifest not found.", path)
return