diff --git a/bzz/api.go b/bzz/api.go index 356720d19d..38fcf6933e 100644 --- a/bzz/api.go +++ b/bzz/api.go @@ -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 { diff --git a/bzz/manifest.go b/bzz/manifest.go index 6416530e3e..47b9d99ebb 100644 --- a/bzz/manifest.go +++ b/bzz/manifest.go @@ -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,10 +26,19 @@ 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 { - dpaLogger.Debugf("Swarm: '%s' matches '%s'.", path, entry.Path) - return + 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