Replace 'path' with 'file/path'

This commit is contained in:
mariusor 2022-11-03 14:53:54 +01:00
parent e2b6e01b27
commit 1c6c4d8444
No known key found for this signature in database
GPG key ID: 35D8720425890EF7
2 changed files with 8 additions and 8 deletions

10
iri.go
View file

@ -6,7 +6,7 @@ import (
"fmt"
"io"
"net/url"
"path"
"path/filepath"
"strings"
"github.com/valyala/fastjson"
@ -134,7 +134,7 @@ func (i *IRIs) GobDecode(data []byte) error {
// AddPath concatenates el elements as a path to i
func (i IRI) AddPath(el ...string) IRI {
return IRI(fmt.Sprintf("%s/%s", i, path.Join(el...)))
return IRI(filepath.Clean(filepath.Join(i.String(), filepath.Join(el...))))
}
// GetID
@ -250,7 +250,7 @@ func (i IRI) Equals(with IRI, checkScheme bool) bool {
if strings.ToLower(u.Host) != strings.ToLower(uw.Host) {
return false
}
if path.Clean(u.Path) != path.Clean(uw.Path) {
if filepath.Clean(u.Path) != filepath.Clean(uw.Path) {
return false
}
uq := u.Query()
@ -311,11 +311,11 @@ func (i IRI) Contains(what IRI, checkScheme bool) bool {
}
p := u.Path
if p != "" {
p = path.Clean(p)
p = filepath.Clean(p)
}
pw := uw.Path
if pw != "" {
pw = path.Clean(pw)
pw = filepath.Clean(pw)
}
return strings.Contains(p, pw)
}

View file

@ -2,7 +2,7 @@ package activitypub
import (
"fmt"
"path"
"path/filepath"
"strings"
"github.com/go-ap/errors"
@ -71,7 +71,7 @@ func (t CollectionPaths) Contains(typ CollectionPath) bool {
// Split splits the IRI in an actor IRI and its CollectionPath
// if the CollectionPath is found in the elements in the t CollectionPaths slice
func (t CollectionPaths) Split(i IRI) (IRI, CollectionPath) {
maybeActor, maybeCol := path.Split(i.String())
maybeActor, maybeCol := filepath.Split(i.String())
tt := CollectionPath(maybeCol)
if !t.Contains(tt) {
tt = ""
@ -144,7 +144,7 @@ func (t CollectionPath) Of(i Item) Item {
// OfActor returns the base IRI of received i, if i represents an IRI matching CollectionPath type t
func (t CollectionPath) OfActor(i IRI) (IRI, error) {
maybeActor, maybeCol := path.Split(i.String())
maybeActor, maybeCol := filepath.Split(i.String())
if strings.ToLower(maybeCol) == strings.ToLower(string(t)) {
maybeActor = strings.TrimRight(maybeActor, "/")
return IRI(maybeActor), nil