mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fix manifest path matching slashes issue
This commit is contained in:
parent
0501ff41d0
commit
38d1bdf688
2 changed files with 22 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,17 @@ package bzz
|
|||
|
||||
import (
|
||||
// "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
|
||||
|
|
|
|||
Loading…
Reference in a new issue