Skip to content

Commit 7b38742

Browse files
authored
Merge pull request ipfs/kubo#6122 from ipfs/feat/coreapi/path-errs
coreapi: Drop error from ParsePath This commit was moved from ipfs/kubo@c8e34bc
2 parents d724a2c + 6832490 commit 7b38742

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

gateway/core/corehttp/gateway_handler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
ft "github.com/ipfs/go-unixfs"
2727
"github.com/ipfs/go-unixfs/importer"
2828
coreiface "github.com/ipfs/interface-go-ipfs-core"
29+
ipath "github.com/ipfs/interface-go-ipfs-core/path"
2930
"github.com/libp2p/go-libp2p-routing"
3031
"github.com/multiformats/go-multibase"
3132
)
@@ -147,8 +148,8 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
147148
ipnsHostname = true
148149
}
149150

150-
parsedPath, err := coreiface.ParsePath(urlPath)
151-
if err != nil {
151+
parsedPath := ipath.New(urlPath)
152+
if err := parsedPath.IsValid(); err != nil {
152153
webError(w, "invalid ipfs path", err, http.StatusBadRequest)
153154
return
154155
}
@@ -246,7 +247,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
246247
return
247248
}
248249

249-
idx, err := i.api.Unixfs().Get(ctx, coreiface.Join(resolvedPath, "index.html"))
250+
idx, err := i.api.Unixfs().Get(ctx, ipath.Join(resolvedPath, "index.html"))
250251
switch err.(type) {
251252
case nil:
252253
dirwithoutslash := urlPath[len(urlPath)-1] != '/'

gateway/core/corehttp/gateway_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
path "github.com/ipfs/go-path"
2424
iface "github.com/ipfs/interface-go-ipfs-core"
2525
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
26+
ipath "github.com/ipfs/interface-go-ipfs-core/path"
2627
ci "github.com/libp2p/go-libp2p-crypto"
2728
id "github.com/libp2p/go-libp2p/p2p/protocol/identify"
2829
)
@@ -344,12 +345,12 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
344345
t.Fatal(err)
345346
}
346347

347-
k2, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'"))
348+
k2, err := api.ResolvePath(ctx, ipath.Join(k, "foo? #<'"))
348349
if err != nil {
349350
t.Fatal(err)
350351
}
351352

352-
k3, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'/bar"))
353+
k3, err := api.ResolvePath(ctx, ipath.Join(k, "foo? #<'/bar"))
353354
if err != nil {
354355
t.Fatal(err)
355356
}

0 commit comments

Comments
 (0)