diff --git a/core/commands/publish.go b/core/commands/publish.go index 03f24dcdb8162814f9fb48315971c78ca492e871..bef930bd9299041f1fbf072310c0b8b3284ae27a 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -107,9 +107,15 @@ Publish an <ipfs-path> to another public key (not implemented): } func publish(n *core.IpfsNode, k crypto.PrivKey, ref path.Path) (*IpnsEntry, error) { + // First, verify the path exists + _, err := n.Resolver.ResolvePath(ref) + if err != nil { + return nil, err + } + pub := nsys.NewRoutingPublisher(n.Routing) - err := pub.Publish(n.Context(), k, ref) + err = pub.Publish(n.Context(), k, ref) if err != nil { return nil, err } diff --git a/core/corehttp/ipns_hostname.go b/core/corehttp/ipns_hostname.go index abfcf4a638ad1a1603961395ca64cf42e5097841..7361001d1e46b317a8cff78ac5f7d40eda1cfb88 100644 --- a/core/corehttp/ipns_hostname.go +++ b/core/corehttp/ipns_hostname.go @@ -19,8 +19,8 @@ func IPNSHostnameOption() ServeOption { defer cancel() host := strings.SplitN(r.Host, ":", 2)[0] - if k, err := n.Namesys.Resolve(ctx, host); err == nil { - r.URL.Path = "/ipfs/" + k.String() + r.URL.Path + if p, err := n.Namesys.Resolve(ctx, host); err == nil { + r.URL.Path = "/ipfs/" + p.String() + r.URL.Path } childMux.ServeHTTP(w, r) }) diff --git a/path/path.go b/path/path.go index f7d4e43ff3e6e67fbf498a73b731b48826738c0e..e61a061930f3a9ced3e67f8d9d6004200ad03c57 100644 --- a/path/path.go +++ b/path/path.go @@ -49,11 +49,13 @@ func FromSegments(seg ...string) Path { } func ParsePath(txt string) (Path, error) { - kp, err := ParseKeyToPath(txt) - if err == nil { - return kp, nil - } parts := strings.Split(txt, "/") + if len(parts) == 1 { + kp, err := ParseKeyToPath(txt) + if err == nil { + return kp, nil + } + } if len(parts) < 3 { return "", ErrBadPath } @@ -66,7 +68,7 @@ func ParsePath(txt string) (Path, error) { return "", ErrBadPath } - _, err = ParseKeyToPath(parts[2]) + _, err := ParseKeyToPath(parts[2]) if err != nil { return "", err } @@ -86,3 +88,8 @@ func ParseKeyToPath(txt string) (Path, error) { } return FromKey(u.Key(chk)), nil } + +func (p *Path) IsValid() error { + _, err := ParsePath(p.String()) + return err +}