refactor: support percent-encoded /unix paths#10833
Conversation
This is a PoC that aims to support multiformats/multiaddr#174 while not breaking existing Kubo users. See TODO in daemon.go – likely we want to move this to https://github.com/multiformats/go-multiaddr
| // TODO: should a version of this live in https://github.com/multiformats/go-multiaddr | ||
| // so we dont need to duplicate code here and in client/rpc/api.go ? | ||
| func NormalizeUnixMultiaddr(address string) string { | ||
| // Support legacy and modern /unix addrs | ||
| // https://github.com/multiformats/multiaddr/pull/174 | ||
| socketPath, err := url.PathUnescape(address) | ||
| if err != nil { | ||
| return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err) | ||
| } | ||
| // Ensure the path is absolute | ||
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { | ||
| socketPath = string(filepath.Separator) + socketPath | ||
| } | ||
| // Normalize path | ||
| socketPath = filepath.Clean(socketPath) | ||
| return socketPath | ||
| } | ||
|
|
There was a problem hiding this comment.
IF It does not live in https://github.com/multiformats/go-multiaddr then multiformats/multiaddr#174 is effectively a dead spec IMO, because nobody will use percent-encoded version.
There was a problem hiding this comment.
I agree. If we are going to support multiformats/multiaddr#174 then this should live in go-multiaddr
| if err != nil { | ||
| return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err) | ||
| } | ||
| // Ensure the path is absolute |
There was a problem hiding this comment.
N.b. in the latest version of the spec pr, relative paths are supported
| return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err) | ||
| } | ||
| // Ensure the path is absolute | ||
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { |
There was a problem hiding this comment.
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { | |
| if !filepath.IsAbs(socketPath) { |
| } | ||
| // Ensure the path is absolute | ||
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { | ||
| socketPath = string(filepath.Separator) + socketPath |
There was a problem hiding this comment.
Is it correct to prepend a separator, or should the current directory be prepended?
See filepath.Abs
| socketPath = filepath.Clean(socketPath) | ||
| return socketPath |
There was a problem hiding this comment.
| socketPath = filepath.Clean(socketPath) | |
| return socketPath | |
| return filepath.Clean(socketPath) |
| // TODO: should a version of this live in https://github.com/multiformats/go-multiaddr | ||
| // so we dont need to duplicate code here and in client/rpc/api.go ? | ||
| func NormalizeUnixMultiaddr(address string) string { | ||
| // Support legacy and modern /unix addrs | ||
| // https://github.com/multiformats/multiaddr/pull/174 | ||
| socketPath, err := url.PathUnescape(address) | ||
| if err != nil { | ||
| return address // nil, fmt.Errorf("failed to unescape /unix socket path: %w", err) | ||
| } | ||
| // Ensure the path is absolute | ||
| if !strings.HasPrefix(socketPath, string(filepath.Separator)) { | ||
| socketPath = string(filepath.Separator) + socketPath | ||
| } | ||
| // Normalize path | ||
| socketPath = filepath.Clean(socketPath) | ||
| return socketPath | ||
| } | ||
|
|
There was a problem hiding this comment.
I agree. If we are going to support multiformats/multiaddr#174 then this should live in go-multiaddr
Why
/unixmultiformats/multiaddr#174is breaking spec change that is incompatible with existing feature in Kubo, where users were able to provide old notation of
/unixmultiaddrs in both Addresses.API and Addresses.Gateway.How
This is a PoC that aims to support
multiformats/multiaddr#174 while not breaking existing Kubo users.
TODO